Added a Refrenced::getGlobalReferencedMutex, and OpenThreads::ScopedPointerLock() and use of this in add/removeParent() codes
to avoid threading problems when using atomic ref counting.
This commit is contained in:
@@ -43,5 +43,28 @@ template <class M> class ReverseScopedLock
|
||||
~ReverseScopedLock(){m_lock.lock();}
|
||||
};
|
||||
|
||||
|
||||
template <class M> class ScopedPointerLock
|
||||
{
|
||||
private:
|
||||
M* m_lock;
|
||||
ScopedPointerLock(const ScopedPointerLock&); // prevent copy
|
||||
ScopedPointerLock& operator=(const ScopedPointerLock&); // prevent assign
|
||||
public:
|
||||
explicit ScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->lock();}
|
||||
~ScopedPointerLock(){ if (m_lock) m_lock->unlock();}
|
||||
};
|
||||
|
||||
template <class M> class ReverseScopedPointerLock
|
||||
{
|
||||
private:
|
||||
M* m_lock;
|
||||
ReverseScopedPointerLock(const ReverseScopedPointerLock&); // prevent copy
|
||||
ReverseScopedPointerLock& operator=(const ReverseScopedPointerLock&); // prevent assign
|
||||
public:
|
||||
explicit ReverseScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->unlock();}
|
||||
~ReverseScopedPointerLock(){ if (m_lock) m_lock->lock();}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -70,11 +70,14 @@ class OSG_EXPORT Referenced
|
||||
|
||||
/** Get the mutex used to ensure thread safety of ref()/unref(). */
|
||||
#if defined(_OSG_REFERENCED_USE_ATOMIC_OPERATIONS)
|
||||
OpenThreads::Mutex* getRefMutex() const { return 0; }
|
||||
OpenThreads::Mutex* getRefMutex() const { return getGlobalReferencedMutex(); }
|
||||
#else
|
||||
OpenThreads::Mutex* getRefMutex() const { return _refMutex; }
|
||||
#endif
|
||||
|
||||
/** Get the optional global Referenced mutex, this can be shared between all osg::Referenced.*/
|
||||
static OpenThreads::Mutex* getGlobalReferencedMutex();
|
||||
|
||||
/** Increment the reference count by one, indicating that
|
||||
this object has another pointer which is referencing it.*/
|
||||
inline void ref() const;
|
||||
|
||||
Reference in New Issue
Block a user