Refactored the osg::Observer to introduce a new bool Observer::objectUnreferenced(void*) method that adds
the extra capability of making it possible for Observers to assume ownership of a object that would otherwsie be deleted. Added a thread safe ref_ptr<T> observer_ptr<T>::lock() method for robust access to an observed object. This makes observer_ptr<> more equivilant to boosts weak_ptr.
This commit is contained in:
@@ -122,7 +122,9 @@ class OSG_EXPORT Referenced
|
||||
protected:
|
||||
|
||||
virtual ~Referenced();
|
||||
|
||||
|
||||
void signalObserversAndDelete(bool signalUnreferened, bool signalDelete, bool doDelete) const;
|
||||
|
||||
void deleteUsingDeleteHandler() const;
|
||||
|
||||
#if defined(_OSG_REFERENCED_USE_ATOMIC_OPERATIONS)
|
||||
@@ -161,26 +163,23 @@ inline void Referenced::ref() const
|
||||
inline void Referenced::unref() const
|
||||
{
|
||||
#if defined(_OSG_REFERENCED_USE_ATOMIC_OPERATIONS)
|
||||
bool needDelete = (--_refCount == 0);
|
||||
bool needDelete = (--_refCount <= 0);
|
||||
#else
|
||||
bool needDelete = false;
|
||||
if (_refMutex)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*_refMutex);
|
||||
--_refCount;
|
||||
needDelete = _refCount<=0;
|
||||
needDelete = (--_refCount)<=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
--_refCount;
|
||||
needDelete = _refCount<=0;
|
||||
needDelete = (--_refCount)<=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (needDelete)
|
||||
{
|
||||
if (getDeleteHandler()) deleteUsingDeleteHandler();
|
||||
else delete this;
|
||||
signalObserversAndDelete(true,true,true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user