Better macro support for switching on/off use of mutex
This commit is contained in:
parent
cf41e73ccc
commit
7126ca44e9
@ -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 )
|
||||
|
@ -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;
|
||||
|
@ -20,8 +20,11 @@
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
// #define THREAD_SAFE_GLOBJECT_DELETE_LISTS 1
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
// forward declare State & StateSet
|
||||
class State;
|
||||
class StateSet;
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <OpenThreads/Mutex>
|
||||
#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
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -26,6 +26,11 @@
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <OpenThreads/Mutex>
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
@ -34,14 +39,17 @@ using namespace osg;
|
||||
typedef std::list<GLuint> DisplayListList;
|
||||
typedef std::map<GLuint,DisplayListList> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(s_mutex_deletedVertexBufferObjectCache);
|
||||
#endif
|
||||
|
||||
|
@ -18,6 +18,11 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <OpenThreads/Mutex>
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
// static cache of deleted fragment programs which can only
|
||||
@ -26,14 +31,16 @@ using namespace osg;
|
||||
typedef std::list<GLuint> FragmentProgramObjectList;
|
||||
typedef std::map<unsigned int,FragmentProgramObjectList> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(s_mutex_deletedFragmentProgramObjectCache);
|
||||
#endif
|
||||
|
||||
|
@ -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<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(getTextureObjectManager()->_mutex);
|
||||
#endif
|
||||
|
||||
getTextureObjectManager()->_textureObjectListMap[contextID].push_back(_textureObjectBuffer[contextID]);
|
||||
_textureObjectBuffer[contextID] = 0;
|
||||
|
@ -18,6 +18,11 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <OpenThreads/Mutex>
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
// static cache of deleted vertex programs which can only
|
||||
@ -26,14 +31,16 @@ using namespace osg;
|
||||
typedef std::list<GLuint> VertexProgramObjectList;
|
||||
typedef std::map<unsigned int,VertexProgramObjectList> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(s_mutex_deletedVertexProgramObjectCache);
|
||||
#endif
|
||||
|
||||
|
@ -31,6 +31,11 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <OpenThreads/Mutex>
|
||||
#endif
|
||||
|
||||
using namespace osgGL2;
|
||||
|
||||
|
||||
@ -76,14 +81,16 @@ private:
|
||||
typedef std::list<GLhandleARB> GL2ObjectList;
|
||||
typedef std::map<unsigned int, GL2ObjectList> 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<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(s_mutex_deletedGL2ObjectCache);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user