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

Replace std::mutex with absl::Mutex in llapr for faster locking/unlocking on msvc...

parent 36aa62d7
No related branches found
No related tags found
No related merge requests found
...@@ -151,7 +151,7 @@ LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size ...@@ -151,7 +151,7 @@ LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size
//create mutex //create mutex
if(!is_local) //not a local apr_pool, that is: shared by multiple threads. if(!is_local) //not a local apr_pool, that is: shared by multiple threads.
{ {
mMutexp.reset(new std::mutex()); mMutexp = std::make_unique<absl::Mutex>();
} }
} }
...@@ -172,7 +172,7 @@ apr_pool_t* LLVolatileAPRPool::getAPRPool() ...@@ -172,7 +172,7 @@ apr_pool_t* LLVolatileAPRPool::getAPRPool()
apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool() apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
{ {
LLScopedLock lock(mMutexp.get()) ; absl::MutexLockMaybe lock(mMutexp.get()) ;
mNumTotalRef++ ; mNumTotalRef++ ;
mNumActiveRef++ ; mNumActiveRef++ ;
...@@ -187,7 +187,7 @@ apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool() ...@@ -187,7 +187,7 @@ apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
void LLVolatileAPRPool::clearVolatileAPRPool() void LLVolatileAPRPool::clearVolatileAPRPool()
{ {
LLScopedLock lock(mMutexp.get()); absl::MutexLockMaybe lock(mMutexp.get());
if(mNumActiveRef > 0) if(mNumActiveRef > 0)
{ {
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "llstring.h" #include "llstring.h"
#include "mutex.h" #include "absl/synchronization/mutex.h"
struct apr_dso_handle_t; struct apr_dso_handle_t;
/** /**
...@@ -117,7 +117,7 @@ class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool ...@@ -117,7 +117,7 @@ class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool
S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool. S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool.
S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating. S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating.
std::unique_ptr<std::mutex> mMutexp; std::unique_ptr<absl::Mutex> mMutexp;
} ; } ;
// File IO convenience functions. // File IO convenience functions.
......
...@@ -182,36 +182,4 @@ LLMutexTrylock::~LLMutexTrylock() ...@@ -182,36 +182,4 @@ LLMutexTrylock::~LLMutexTrylock()
mMutex->unlock(); mMutex->unlock();
} }
//---------------------------------------------------------------------
//
// LLScopedLock
//
LLScopedLock::LLScopedLock(std::mutex* mutex) : mMutex(mutex)
{
if(mutex)
{
mutex->lock();
mLocked = true;
}
else
{
mLocked = false;
}
}
LLScopedLock::~LLScopedLock()
{
unlock();
}
void LLScopedLock::unlock()
{
if(mLocked)
{
mMutex->unlock();
mLocked = false;
}
}
//============================================================================ //============================================================================
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "stdtypes.h" #include "stdtypes.h"
#include "llthread.h" #include "llthread.h"
#include <boost/noncopyable.hpp>
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
...@@ -187,46 +186,6 @@ namespace llthread ...@@ -187,46 +186,6 @@ namespace llthread
}; };
} }
/**
* @class LLScopedLock
* @brief Small class to help lock and unlock mutexes.
*
* The constructor handles the lock, and the destructor handles
* the unlock. Instances of this class are <b>not</b> thread safe.
*/
class LL_COMMON_API LLScopedLock : private boost::noncopyable
{
public:
/**
* @brief Constructor which accepts a mutex, and locks it.
*
* @param mutex An allocated mutex. If you pass in NULL,
* this wrapper will not lock.
*/
LLScopedLock(std::mutex* mutex);
/**
* @brief Destructor which unlocks the mutex if still locked.
*/
~LLScopedLock();
/**
* @brief Check lock.
*/
bool isLocked() const { return mLocked; }
/**
* @brief This method unlocks the mutex.
*/
void unlock();
protected:
bool mLocked;
std::mutex* mMutex;
};
class AbslMutexMaybeTrylock class AbslMutexMaybeTrylock
{ {
public: public:
......
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