From 9e180e501c00cd03014e2f0dc9a2fd81ecfbefa2 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 20 Oct 2020 12:31:10 -0400
Subject: [PATCH] Replace std::mutex with absl::Mutex in llapr for faster
 locking/unlocking on msvc...

---
 indra/llcommon/llapr.cpp   |  6 +++---
 indra/llcommon/llapr.h     |  4 ++--
 indra/llcommon/llmutex.cpp | 32 -----------------------------
 indra/llcommon/llmutex.h   | 41 --------------------------------------
 4 files changed, 5 insertions(+), 78 deletions(-)

diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp
index 984e90f3762..a2233692c63 100644
--- a/indra/llcommon/llapr.cpp
+++ b/indra/llcommon/llapr.cpp
@@ -151,7 +151,7 @@ LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size
 	//create mutex
 	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()
 
 apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool() 
 {	
-	LLScopedLock lock(mMutexp.get()) ;
+	absl::MutexLockMaybe lock(mMutexp.get()) ;
 
 	mNumTotalRef++ ;
 	mNumActiveRef++ ;
@@ -187,7 +187,7 @@ apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
 
 void LLVolatileAPRPool::clearVolatileAPRPool() 
 {
-    LLScopedLock lock(mMutexp.get());
+	absl::MutexLockMaybe lock(mMutexp.get());
 
 	if(mNumActiveRef > 0)
 	{
diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h
index 255b50c8d04..7de47914783 100644
--- a/indra/llcommon/llapr.h
+++ b/indra/llcommon/llapr.h
@@ -41,7 +41,7 @@
 
 #include "llstring.h"
 
-#include "mutex.h"
+#include "absl/synchronization/mutex.h"
 
 struct apr_dso_handle_t;
 /**
@@ -117,7 +117,7 @@ class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool
 	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.  
 
-	std::unique_ptr<std::mutex> mMutexp;
+	std::unique_ptr<absl::Mutex> mMutexp;
 } ;
 
 // File IO convenience functions.
diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp
index f32aaad1df1..70655a43337 100644
--- a/indra/llcommon/llmutex.cpp
+++ b/indra/llcommon/llmutex.cpp
@@ -182,36 +182,4 @@ LLMutexTrylock::~LLMutexTrylock()
         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;
-	}
-}
-
 //============================================================================
diff --git a/indra/llcommon/llmutex.h b/indra/llcommon/llmutex.h
index dd09cc10c5e..ec2166d3686 100644
--- a/indra/llcommon/llmutex.h
+++ b/indra/llcommon/llmutex.h
@@ -29,7 +29,6 @@
 
 #include "stdtypes.h"
 #include "llthread.h"
-#include <boost/noncopyable.hpp>
 
 #include "absl/synchronization/mutex.h"
 
@@ -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
 {
 public:
-- 
GitLab