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

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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