From b2c3a90adfb6c0285d02355fd8ab061b7f2f1e6c Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 8 May 2014 01:42:25 +0200 Subject: [PATCH] Fix use count for deleted, reference counted objects. Remove inconsitency of returning 0 or ~0. If the object has been deleted there are no more references, so always return 0. --- simgear/structure/SGReferenced.hxx | 6 +++--- simgear/structure/SGWeakReferenced.hxx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/simgear/structure/SGReferenced.hxx b/simgear/structure/SGReferenced.hxx index 69788b3f..67e4fb1e 100644 --- a/simgear/structure/SGReferenced.hxx +++ b/simgear/structure/SGReferenced.hxx @@ -42,11 +42,11 @@ public: { return *this; } static unsigned get(const SGReferenced* ref) - { if (ref) return ++(ref->_refcount); else return ~0u; } + { if (ref) return ++(ref->_refcount); else return 0; } static unsigned put(const SGReferenced* ref) - { if (ref) return --(ref->_refcount); else return ~0u; } + { if (ref) return --(ref->_refcount); else return 0; } static unsigned count(const SGReferenced* ref) - { if (ref) return ref->_refcount; else return ~0u; } + { if (ref) return ref->_refcount; else return 0; } static bool shared(const SGReferenced* ref) { if (ref) return 1u < ref->_refcount; else return false; } diff --git a/simgear/structure/SGWeakReferenced.hxx b/simgear/structure/SGWeakReferenced.hxx index dbe50574..7a2bcaf5 100644 --- a/simgear/structure/SGWeakReferenced.hxx +++ b/simgear/structure/SGWeakReferenced.hxx @@ -71,11 +71,11 @@ public: /// The usual operations on weak pointers. /// The interface should stay the same then what we have in Referenced. static unsigned get(const SGWeakReferenced* ref) - { if (ref) return ++(ref->mWeakData->mRefcount); else return 0u; } + { if (ref) return ++(ref->mWeakData->mRefcount); else return 0; } static unsigned put(const SGWeakReferenced* ref) - { if (ref) return --(ref->mWeakData->mRefcount); else return ~0u; } + { if (ref) return --(ref->mWeakData->mRefcount); else return 0; } static unsigned count(const SGWeakReferenced* ref) - { if (ref) return ref->mWeakData->mRefcount; else return 0u; } + { if (ref) return ref->mWeakData->mRefcount; else return 0; } private: /// Support for weak references, not increasing the reference count -- 2.39.5