diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 2ef473911..d6347729c 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -54,7 +54,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 opengl32.lib glu32.lib /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osg.dll" +# ADD LINK32 OpenThreadsWin32.lib opengl32.lib glu32.lib /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osg.dll" !ELSEIF "$(CFG)" == "Core osg - Win32 Debug" @@ -81,7 +81,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 opengl32.lib glu32.lib /nologo /dll /pdb:"../../bin/osgd.pdb" /debug /machine:I386 /out:"../../bin/osgd.dll" /pdbtype:sept +# ADD LINK32 OpenThreadsWin32d.lib opengl32.lib glu32.lib /nologo /dll /pdb:"../../bin/osgd.pdb" /debug /machine:I386 /out:"../../bin/osgd.dll" /pdbtype:sept # SUBTRACT LINK32 /pdb:none /incremental:no !ENDIF diff --git a/include/osg/Referenced b/include/osg/Referenced index 99901a196..d4593a6e8 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -14,8 +14,13 @@ #ifndef OSG_REFERENCED #define OSG_REFERENCED 1 +#include +#include + #include +#define USE_REF_MUTEX 1 + namespace osg { @@ -51,7 +56,13 @@ class SG_EXPORT Referenced /** increment the reference count by one, indicating that this object has another pointer which is referencing it.*/ - inline void ref() const { ++_refCount; } + inline void ref() const + { +#ifdef USE_REF_MUTEX + OpenThreads::ScopedLock lock(_refMutex); +#endif + ++_refCount; + } /** decrement the reference count by one, indicating that a pointer to this object is referencing it. If the @@ -73,7 +84,11 @@ class SG_EXPORT Referenced protected: virtual ~Referenced(); - mutable int _refCount; + +#ifdef USE_REF_MUTEX + mutable OpenThreads::Mutex _refMutex; +#endif + mutable int _refCount; }; @@ -105,16 +120,19 @@ class DeleteHandler inline void Referenced::unref() const { - --_refCount; - if (_refCount==0) + bool needDelete = false; + { +#ifdef USE_REF_MUTEX + OpenThreads::ScopedLock lock(_refMutex); +#endif + --_refCount; + needDelete = _refCount<=0; + } + if (needDelete) { if (getDeleteHandler()) getDeleteHandler()->requestDelete(this); else delete this; } - else if (_refCount<0) - { - throw 2325; - } } }