From 1b67931f1646d4ca3a472ac2ba1b29f87a0b979c Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 14 Mar 2020 14:59:20 +0100 Subject: [PATCH] express: invert return value of unref_if_one() This is more consistent with how the return value of unref() works. Someone might otherwise trip over this. --- panda/src/express/referenceCount.I | 4 ++-- panda/src/pgraph/renderAttrib.cxx | 2 +- panda/src/pgraph/renderState.cxx | 2 +- panda/src/pgraph/transformState.cxx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/panda/src/express/referenceCount.I b/panda/src/express/referenceCount.I index 6b5847407c..f4d71b1117 100644 --- a/panda/src/express/referenceCount.I +++ b/panda/src/express/referenceCount.I @@ -321,7 +321,7 @@ ref_if_nonzero() const { * Atomically decreases the reference count of this object if it is one. * Do not use this. This exists only to implement a special case with the * state cache. - * @return true if the reference count was decremented to zero. + * @return false if the reference count was decremented to zero. */ INLINE bool ReferenceCount:: unref_if_one() const { @@ -329,7 +329,7 @@ unref_if_one() const { nassertr(test_ref_count_integrity(), 0); nassertr(_ref_count > 0, 0); #endif - return (AtomicAdjust::compare_and_exchange(_ref_count, 1, 0) == 1); + return (AtomicAdjust::compare_and_exchange(_ref_count, 1, 0) != 1); } /** diff --git a/panda/src/pgraph/renderAttrib.cxx b/panda/src/pgraph/renderAttrib.cxx index 9b5bbd6303..9c9d9e167b 100644 --- a/panda/src/pgraph/renderAttrib.cxx +++ b/panda/src/pgraph/renderAttrib.cxx @@ -215,7 +215,7 @@ garbage_collect() { do { RenderAttrib *attrib = (RenderAttrib *)_attribs->get_key(si); - if (attrib->unref_if_one()) { + if (!attrib->unref_if_one()) { // This attrib has recently been unreffed to 1 (the one we added when // we stored it in the cache). Now it's time to delete it. This is // safe, because we're holding the _attribs_lock, so it's not possible diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index 5098f9dc34..fdc187ecbb 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -934,7 +934,7 @@ garbage_collect() { } } - if (state->unref_if_one()) { + if (!state->unref_if_one()) { // This state has recently been unreffed to 1 (the one we added when // we stored it in the cache). Now it's time to delete it. This is // safe, because we're holding the _states_lock, so it's not possible diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index 220c9c5d8b..efbb97f2bb 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -1204,7 +1204,7 @@ garbage_collect() { } } - if (state->unref_if_one()) { + if (!state->unref_if_one()) { // This state has recently been unreffed to 1 (the one we added when // we stored it in the cache). Now it's time to delete it. This is // safe, because we're holding the _states_lock, so it's not possible