Skip to content
Snippets Groups Projects
Commit ae325716 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Swap LLMutex impl to recursive_mutex to avoid reinventing the wheel

parent e01309b7
No related branches found
No related tags found
No related merge requests found
......@@ -34,43 +34,12 @@
void LLMutex::lock()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if(isSelfLocked())
{ //redundant lock
mCount++;
return;
}
mMutex.lock();
#if MUTEX_DEBUG
// Have to have the lock before we can access the debug info
auto id = LLThread::currentID();
if (mIsLocked[id] != FALSE)
LL_ERRS() << "Already locked in Thread: " << id << LL_ENDL;
mIsLocked[id] = TRUE;
#endif
mLockingThread = LLThread::currentID();
}
void LLMutex::unlock()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if (mCount > 0)
{ //not the root unlock
mCount--;
return;
}
#if MUTEX_DEBUG
// Access the debug info while we have the lock
auto id = LLThread::currentID();
if (mIsLocked[id] != TRUE)
LL_ERRS() << "Not locked in Thread: " << id << LL_ENDL;
mIsLocked[id] = FALSE;
#endif
mLockingThread = LLThread::id_t();
mMutex.unlock();
}
......@@ -88,40 +57,10 @@ bool LLMutex::isLocked()
}
}
bool LLMutex::isSelfLocked()
{
return mLockingThread == LLThread::currentID();
}
LLThread::id_t LLMutex::lockingThread() const
{
return mLockingThread;
}
bool LLMutex::try_lock()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if(isSelfLocked())
{ //redundant lock
mCount++;
return true;
}
if (!mMutex.try_lock())
{
return false;
}
#if MUTEX_DEBUG
// Have to have the lock before we can access the debug info
auto id = LLThread::currentID();
if (mIsLocked[id] != FALSE)
LL_ERRS() << "Already locked in Thread: " << id << LL_ENDL;
mIsLocked[id] = TRUE;
#endif
mLockingThread = LLThread::currentID();
return true;
return mMutex.try_lock();
}
//============================================================================
......@@ -135,7 +74,7 @@ LLCondition::LLCondition() :
void LLCondition::wait()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
std::unique_lock< std::shared_mutex > lock(mMutex);
std::unique_lock<std::recursive_mutex> lock(mMutex);
mCond.wait(lock);
}
......
......@@ -52,17 +52,9 @@ class LL_COMMON_API LLMutex
bool try_lock(); // non-blocking, returns true if lock held.
void unlock(); // undefined behavior when called on mutex not being held
bool isLocked(); // non-blocking, but does do a lock/unlock so not free
bool isSelfLocked(); //return true if locked in a same thread
LLThread::id_t lockingThread() const; //get ID of locking thread
protected:
std::shared_mutex mMutex;
mutable U32 mCount = 0;
mutable LLThread::id_t mLockingThread;
#if MUTEX_DEBUG
std::map<LLThread::id_t, BOOL> mIsLocked;
#endif
std::recursive_mutex mMutex;
};
// Actually a condition/mutex pair (since each condition needs to be associated with a mutex).
......
......@@ -31,11 +31,10 @@
#include <list>
#include <typeinfo>
#include <vector>
#include <shared_mutex>
#include "mutex.h"
#include "lockstatic.h"
#include "llthread.h" // on_main_thread()
#include "llmainthreadtask.h"
#include "llmutex.h"
class LLSingletonBase: private boost::noncopyable
{
......@@ -293,7 +292,7 @@ class LLSingleton : public LLSingletonBase
{
// Use a recursive_mutex in case of constructor circularity. With a
// non-recursive mutex, that would result in deadlock.
typedef LLMutex mutex_t;
typedef std::recursive_mutex mutex_t;
mutex_t mMutex; // LockStatic looks for mMutex
EInitState mInitState{UNINITIALIZED};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment