From 7126ca44e9e488960889aafdb3dcb07d7bf5d5ea Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Aug 2004 11:01:39 +0000 Subject: [PATCH] Better macro support for switching on/off use of mutex --- include/osg/Export | 2 +- include/osg/Referenced | 15 +++++++++------ include/osg/StateAttribute | 3 +++ include/osg/Texture | 8 +++++++- include/osgTerrain/DataSet | 2 +- src/osg/Drawable.cpp | 22 ++++++++++++++++------ src/osg/FragmentProgram.cpp | 13 ++++++++++--- src/osg/Texture.cpp | 10 +++++++--- src/osg/VertexProgram.cpp | 13 ++++++++++--- src/osgGL2/ProgramObject.cpp | 13 ++++++++++--- 10 files changed, 74 insertions(+), 27 deletions(-) diff --git a/include/osg/Export b/include/osg/Export index ba3303057..85457383a 100644 --- a/include/osg/Export +++ b/include/osg/Export @@ -17,7 +17,7 @@ // define used to include in API which is being fazed out // if you can compile your apps with this turned off you are // well placed for compatablity with future versions. -#define USE_DEPRECATED_API +// #define USE_DEPRECATED_API #if defined(_MSC_VER) #pragma warning( disable : 4244 ) diff --git a/include/osg/Referenced b/include/osg/Referenced index 70f0439f6..daba13159 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -14,12 +14,15 @@ #ifndef OSG_REFERENCED #define OSG_REFERENCED 1 -#include -#include #include -// #define USE_REF_MUTEX 1 +// #define THREAD_SAFE_REF_UNREF 1 + +#ifdef THREAD_SAFE_REF_UNREF + #include + #include +#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 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 lock(_refMutex); #endif --_refCount; diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 2df62429a..d7522971b 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -20,8 +20,11 @@ #include +// #define THREAD_SAFE_GLOBJECT_DELETE_LISTS 1 + namespace osg { + // forward declare State & StateSet class State; class StateSet; diff --git a/include/osg/Texture b/include/osg/Texture index 34f87b267..e68bc218a 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -24,6 +24,11 @@ #include #include +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + #include + #include +#endif + // if not defined by gl.h use the definition found in: // http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT @@ -661,9 +666,10 @@ class SG_EXPORT Texture : public osg::StateAttribute TextureObjectListMap _textureObjectListMap; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS // mutex to keep access serialized. OpenThreads::Mutex _mutex; - +#endif }; diff --git a/include/osgTerrain/DataSet b/include/osgTerrain/DataSet index 3a14c20f7..971a35c4c 100644 --- a/include/osgTerrain/DataSet +++ b/include/osgTerrain/DataSet @@ -477,7 +477,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced return advanceToNextChild(*_composite,_index); } - inline bool isActive(const CompositeSource& composite,int index) + inline bool isActive(const CompositeSource& /*composite*/,int /*index*/) { return true; } diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index c7a35fec4..a7d720301 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -26,6 +26,11 @@ #include #include +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + #include + #include +#endif + using namespace osg; // static cache of deleted display lists which can only @@ -34,14 +39,17 @@ using namespace osg; typedef std::list DisplayListList; typedef std::map DeletedDisplayListCache; -static OpenThreads::Mutex s_mutex_deletedDisplayListCache; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + static OpenThreads::Mutex s_mutex_deletedDisplayListCache; +#endif + static DeletedDisplayListCache s_deletedDisplayListCache; void Drawable::deleteDisplayList(unsigned int contextID,GLuint globj) { if (globj!=0) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedDisplayListCache); #endif // insert the globj into the cache for the appropriate context. @@ -63,7 +71,7 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID,double /*currentT unsigned int noDeleted = 0; { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedDisplayListCache); #endif @@ -90,14 +98,16 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID,double /*currentT } -static OpenThreads::Mutex s_mutex_deletedVertexBufferObjectCache; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + static OpenThreads::Mutex s_mutex_deletedVertexBufferObjectCache; +#endif static DeletedDisplayListCache s_deletedVertexBufferObjectCache; void Drawable::deleteVertexBufferObject(unsigned int contextID,GLuint globj) { if (globj!=0) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedVertexBufferObjectCache); #endif @@ -119,7 +129,7 @@ void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*c { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedVertexBufferObjectCache); #endif diff --git a/src/osg/FragmentProgram.cpp b/src/osg/FragmentProgram.cpp index d841b35c8..606840458 100644 --- a/src/osg/FragmentProgram.cpp +++ b/src/osg/FragmentProgram.cpp @@ -18,6 +18,11 @@ #include +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + #include + #include +#endif + using namespace osg; // static cache of deleted fragment programs which can only @@ -26,14 +31,16 @@ using namespace osg; typedef std::list FragmentProgramObjectList; typedef std::map DeletedFragmentProgramObjectCache; -static OpenThreads::Mutex s_mutex_deletedFragmentProgramObjectCache; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + static OpenThreads::Mutex s_mutex_deletedFragmentProgramObjectCache; +#endif static DeletedFragmentProgramObjectCache s_deletedFragmentProgramObjectCache; void FragmentProgram::deleteFragmentProgramObject(unsigned int contextID,GLuint handle) { if (handle!=0) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedFragmentProgramObjectCache); #endif @@ -53,7 +60,7 @@ void FragmentProgram::flushDeletedFragmentProgramObjects(unsigned int contextID, double elapsedTime = 0.0; { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedFragmentProgramObjectCache); #endif diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index eff983d94..437d932e0 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -70,7 +70,7 @@ Texture::TextureObject* Texture::TextureObjectManager::reuseTextureObject(unsign GLsizei depth, GLint border) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(_mutex); #endif @@ -98,7 +98,7 @@ Texture::TextureObject* Texture::TextureObjectManager::reuseTextureObject(unsign void Texture::TextureObjectManager::addTextureObjects(Texture::TextureObjectListMap& toblm) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(_mutex); #endif @@ -113,7 +113,9 @@ void Texture::TextureObjectManager::addTextureObjects(Texture::TextureObjectList void Texture::TextureObjectManager::addTextureObjectsFrom(Texture& texture) { +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(_mutex); +#endif texture.takeTextureObjects(_textureObjectListMap); } @@ -129,7 +131,7 @@ void Texture::TextureObjectManager::flushTextureObjects(unsigned int contextID,d double elapsedTime = 0.0; { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(_mutex); #endif @@ -1076,7 +1078,9 @@ void Texture::releaseGLObjects(State* state) const unsigned int contextID = state->getContextID(); if (_textureObjectBuffer[contextID].valid()) { +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(getTextureObjectManager()->_mutex); +#endif getTextureObjectManager()->_textureObjectListMap[contextID].push_back(_textureObjectBuffer[contextID]); _textureObjectBuffer[contextID] = 0; diff --git a/src/osg/VertexProgram.cpp b/src/osg/VertexProgram.cpp index eb143ff72..fa0994e73 100644 --- a/src/osg/VertexProgram.cpp +++ b/src/osg/VertexProgram.cpp @@ -18,6 +18,11 @@ #include +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + #include + #include +#endif + using namespace osg; // static cache of deleted vertex programs which can only @@ -26,14 +31,16 @@ using namespace osg; typedef std::list VertexProgramObjectList; typedef std::map DeletedVertexProgramObjectCache; -static OpenThreads::Mutex s_mutex_deletedVertexProgramObjectCache; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + static OpenThreads::Mutex s_mutex_deletedVertexProgramObjectCache; +#endif static DeletedVertexProgramObjectCache s_deletedVertexProgramObjectCache; void VertexProgram::deleteVertexProgramObject(unsigned int contextID,GLuint handle) { if (handle!=0) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedVertexProgramObjectCache); #endif @@ -53,7 +60,7 @@ void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,doub double elapsedTime = 0.0; { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedVertexProgramObjectCache); #endif diff --git a/src/osgGL2/ProgramObject.cpp b/src/osgGL2/ProgramObject.cpp index bd87d26e8..3abe46356 100644 --- a/src/osgGL2/ProgramObject.cpp +++ b/src/osgGL2/ProgramObject.cpp @@ -31,6 +31,11 @@ #include +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + #include + #include +#endif + using namespace osgGL2; @@ -76,14 +81,16 @@ private: typedef std::list GL2ObjectList; typedef std::map DeletedGL2ObjectCache; -static OpenThreads::Mutex s_mutex_deletedGL2ObjectCache; +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS + static OpenThreads::Mutex s_mutex_deletedGL2ObjectCache; +#endif static DeletedGL2ObjectCache s_deletedGL2ObjectCache; void ProgramObject::deleteObject(unsigned int contextID, GLhandleARB handle) { if (handle!=0) { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedGL2ObjectCache); #endif // add handle to the cache for the appropriate context. @@ -101,7 +108,7 @@ void ProgramObject::flushDeletedGL2Objects(unsigned int contextID,double /*curre double elapsedTime = 0.0; { -#ifdef THREAD_SAFE_DELETE_LISTS +#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS OpenThreads::ScopedLock lock(s_mutex_deletedGL2ObjectCache); #endif