Better macro support for switching on/off use of mutex

This commit is contained in:
Robert Osfield
2004-08-03 11:01:39 +00:00
parent cf41e73ccc
commit 7126ca44e9
10 changed files with 74 additions and 27 deletions

View File

@@ -14,12 +14,15 @@
#ifndef OSG_REFERENCED
#define OSG_REFERENCED 1
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Mutex>
#include <osg/Export>
// #define USE_REF_MUTEX 1
// #define THREAD_SAFE_REF_UNREF 1
#ifdef THREAD_SAFE_REF_UNREF
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Mutex>
#endif
namespace osg {
@@ -58,7 +61,7 @@ class SG_EXPORT Referenced
this object has another pointer which is referencing it.*/
inline void ref() const
{
#ifdef USE_REF_MUTEX
#ifdef THREAD_SAFE_REF_UNREF
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_refMutex);
#endif
++_refCount;
@@ -85,7 +88,7 @@ class SG_EXPORT Referenced
protected:
virtual ~Referenced();
#ifdef USE_REF_MUTEX
#ifdef THREAD_SAFE_REF_UNREF
mutable OpenThreads::Mutex _refMutex;
#endif
mutable int _refCount;
@@ -122,7 +125,7 @@ inline void Referenced::unref() const
{
bool needDelete = false;
{
#ifdef USE_REF_MUTEX
#ifdef THREAD_SAFE_REF_UNREF
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_refMutex);
#endif
--_refCount;