Browse Source

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.
rdb 5 years ago
parent
commit
1b67931f16

+ 2 - 2
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);
 }
 
 /**

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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