From Tim Moore, refactore WeakReference/Referenced to avoid signalling the observers when do a unref_nodelete.

This commit is contained in:
Robert Osfield
2010-05-17 09:03:44 +00:00
parent 4d88ba6efe
commit f832198128
3 changed files with 9 additions and 5 deletions

View File

@@ -89,8 +89,12 @@ class OSG_EXPORT Referenced
not delete it, even if ref count goes to 0. Warning, unref_nodelete()
should only be called if the user knows exactly who will
be responsible for, one should prefer unref() over unref_nodelete()
as the later can lead to memory leaks.*/
int unref_nodelete() const;
as the later can lead to memory leaks.
@param signalObserversOnZeroRefCount - By default true, adjust the reference count and send
any signal to observers if ref count goes to zero.
*/
int unref_nodelete(bool signalObserversOnZeroRefCount = true) const;
/** Return the number pointers currently referencing this object. */
inline int referenceCount() const { return _refCount; }

View File

@@ -47,7 +47,7 @@ struct WeakReference : public Observer, public Referenced
// The object is in the process of being deleted, but our
// objectDeleted() method hasn't been run yet (and we're
// blocking it -- and the final destruction -- with our lock).
_ptr->unref_nodelete();
_ptr->unref_nodelete(false);
return 0;
}
return _ptr;

View File

@@ -334,7 +334,7 @@ void Referenced::setThreadSafeRefUnref(bool threadSafe)
#endif
}
int Referenced::unref_nodelete() const
int Referenced::unref_nodelete(bool signalObserversOnZeroRefCount) const
{
int result;
#if defined(_OSG_REFERENCED_USE_ATOMIC_OPERATIONS)
@@ -355,7 +355,7 @@ int Referenced::unref_nodelete() const
}
#endif
if (needUnreferencedSignal)
if (needUnreferencedSignal && signalObserversOnZeroRefCount)
{
signalObserversAndDelete(true,false,false);
}