From 9a31b7652ecf3cc6098bf9225fed43fbea869859 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2007 20:50:35 +0000 Subject: [PATCH] Added mutex to lock of ReentrantMutex --- include/osgDB/ReentrantMutex | 11 +++++++++-- src/osgDB/ReentrantMutex.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/osgDB/ReentrantMutex b/include/osgDB/ReentrantMutex index 4a0754994..d43b85899 100644 --- a/include/osgDB/ReentrantMutex +++ b/include/osgDB/ReentrantMutex @@ -42,7 +42,9 @@ class OSGDB_EXPORT ReentrantMutex : public OpenThreads::Mutex ReentrantMutex& operator =(const ReentrantMutex&) { return *(this); } OpenThreads::Thread* _threadHoldingMutex; - unsigned int _lockCount; + + OpenThreads::Mutex _lockCountMutex; + unsigned int _lockCount; }; @@ -66,9 +68,14 @@ class OSGDB_EXPORT ReadWriteMutex ReadWriteMutex(const ReadWriteMutex&) {} ReadWriteMutex& operator = (const ReadWriteMutex&) { return *(this); } - + +#if 1 ReentrantMutex _readWriteMutex; ReentrantMutex _readCountMutex; +#else + OpenThreads::Mutex _readWriteMutex; + OpenThreads::Mutex _readCountMutex; +#endif unsigned int _readCount; }; diff --git a/src/osgDB/ReentrantMutex.cpp b/src/osgDB/ReentrantMutex.cpp index 74a652ab8..a0ef6d867 100644 --- a/src/osgDB/ReentrantMutex.cpp +++ b/src/osgDB/ReentrantMutex.cpp @@ -33,6 +33,7 @@ int ReentrantMutex::lock() { if (_threadHoldingMutex==OpenThreads::Thread::CurrentThread() && _lockCount>0) { + OpenThreads::ScopedLock lock(_lockCountMutex); ++_lockCount; return 0; } @@ -41,6 +42,8 @@ int ReentrantMutex::lock() int result = Mutex::lock(); if (result==0) { + OpenThreads::ScopedLock lock(_lockCountMutex); + _threadHoldingMutex = OpenThreads::Thread::CurrentThread(); _lockCount = 1; } @@ -50,6 +53,7 @@ int ReentrantMutex::lock() int ReentrantMutex::unlock() { + OpenThreads::ScopedLock lock(_lockCountMutex); #if 0 if (_threadHoldingMutex==OpenThreads::Thread::CurrentThread() && _lockCount>0) { @@ -82,6 +86,7 @@ int ReentrantMutex::trylock() { if (_threadHoldingMutex==OpenThreads::Thread::CurrentThread() && _lockCount>0) { + OpenThreads::ScopedLock lock(_lockCountMutex); ++_lockCount; return 0; } @@ -90,6 +95,8 @@ int ReentrantMutex::trylock() int result = Mutex::trylock(); if (result==0) { + OpenThreads::ScopedLock lock(_lockCountMutex); + _threadHoldingMutex = OpenThreads::Thread::CurrentThread(); _lockCount = 1; }