Made the osg::Referenced Mutex be declared as a pointer to a Mutex, with the

Mutex allocated dynamically when required. Added the following methods to
help manage the usage of the mutex:

        void setThreadSafeRefUnref(bool threadSafe);

        bool getThreadSafeRefUnref() const;
This commit is contained in:
Robert Osfield
2005-02-22 20:25:58 +00:00
parent 10c3f934f1
commit e01990d419
2 changed files with 63 additions and 23 deletions

View File

@@ -41,30 +41,29 @@ class SG_EXPORT Referenced
public:
Referenced()
{
_refCount=0;
}
Referenced(const Referenced&) {
_refCount=0;
}
Referenced();
Referenced(const Referenced&);
inline Referenced& operator = (const Referenced&) { return *this; }
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
void setThreadSafeRefUnref(bool threadSafe);
/** Get whether a mutex is used to ensure ref() and unref() are thread safe.*/
bool getThreadSafeRefUnref() const { return _refMutex!=0; }
/** increment the reference count by one, indicating that
/** Increment the reference count by one, indicating that
this object has another pointer which is referencing it.*/
void ref() const;
/** decrement the reference count by one, indicating that
/** Decrement the reference count by one, indicating that
a pointer to this object is referencing it. If the
reference count goes to zero, it is assumed that this object
is no longer referenced and is automatically deleted.*/
void unref() const;
/** decrement the reference count by one, indicating that
/** Decrement the reference count by one, indicating that
a pointer to this object is referencing it. However, do
not delete it, even if ref count goes to 0. Warning, unref_nodelete()
should only be called if the user knows exactly who will
@@ -72,7 +71,7 @@ class SG_EXPORT Referenced
as the later can lead to memory leaks.*/
void unref_nodelete() const;
/** return the number pointers currently referencing this object. */
/** Return the number pointers currently referencing this object. */
inline int referenceCount() const { return _refCount; }
@@ -97,9 +96,9 @@ class SG_EXPORT Referenced
protected:
virtual ~Referenced();
mutable OpenThreads::Mutex _refMutex;
mutable OpenThreads::Mutex* _refMutex;
mutable int _refCount;
mutable int _refCount;
};