Added mutex to lock of ReentrantMutex
This commit is contained in:
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
@@ -33,6 +33,7 @@ int ReentrantMutex::lock()
|
||||
{
|
||||
if (_threadHoldingMutex==OpenThreads::Thread::CurrentThread() && _lockCount>0)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lockCountMutex);
|
||||
++_lockCount;
|
||||
return 0;
|
||||
}
|
||||
@@ -41,6 +42,8 @@ int ReentrantMutex::lock()
|
||||
int result = Mutex::lock();
|
||||
if (result==0)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lockCountMutex);
|
||||
|
||||
_threadHoldingMutex = OpenThreads::Thread::CurrentThread();
|
||||
_lockCount = 1;
|
||||
}
|
||||
@@ -50,6 +53,7 @@ int ReentrantMutex::lock()
|
||||
|
||||
int ReentrantMutex::unlock()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(_lockCountMutex);
|
||||
++_lockCount;
|
||||
return 0;
|
||||
}
|
||||
@@ -90,6 +95,8 @@ int ReentrantMutex::trylock()
|
||||
int result = Mutex::trylock();
|
||||
if (result==0)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_lockCountMutex);
|
||||
|
||||
_threadHoldingMutex = OpenThreads::Thread::CurrentThread();
|
||||
_lockCount = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user