tdf#137544 reduce cost of SolarMutex checking

the  std::thread::id facilities are cheaper than the sal versions

Change-Id: I5ccb7e54f3a1e4d715338faa1e9c0aae9449e46d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136800
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2022-07-04 15:42:15 +02:00
parent d30810b5a1
commit 1a6833a00f
2 changed files with 6 additions and 7 deletions
+4 -5
View File
@@ -38,7 +38,6 @@ SolarMutex *SolarMutex::get()
SolarMutex::SolarMutex()
: m_nCount( 0 )
, m_nThreadId( 0 )
, m_aBeforeReleaseHandler( nullptr )
{
assert(!g_pSolarMutex);
@@ -54,7 +53,7 @@ void SolarMutex::doAcquire( const sal_uInt32 nLockCount )
{
for ( sal_uInt32 n = nLockCount; n ; --n )
m_aMutex.acquire();
m_nThreadId = osl::Thread::getCurrentIdentifier();
m_nThreadId = std::this_thread::get_id();
m_nCount += nLockCount;
}
@@ -72,7 +71,7 @@ sal_uInt32 SolarMutex::doRelease( bool bUnlockAll )
{
if ( m_aBeforeReleaseHandler )
m_aBeforeReleaseHandler();
m_nThreadId = 0;
m_nThreadId = std::thread::id();
}
for ( sal_uInt32 n = nCount ; n ; --n )
@@ -83,14 +82,14 @@ sal_uInt32 SolarMutex::doRelease( bool bUnlockAll )
bool SolarMutex::IsCurrentThread() const
{
return m_nThreadId == osl::Thread::getCurrentIdentifier();
return m_nThreadId == std::this_thread::get_id();
}
bool SolarMutex::tryToAcquire()
{
if ( m_aMutex.tryToAcquire() )
{
m_nThreadId = osl::Thread::getCurrentIdentifier();
m_nThreadId = std::this_thread::get_id();
m_nCount++;
return true;
}
+2 -2
View File
@@ -24,8 +24,8 @@
#include <assert.h>
#include <atomic>
#include <thread>
#include <osl/thread.h>
#include <osl/mutex.hxx>
#include <comphelper/comphelperdllapi.h>
@@ -72,7 +72,7 @@ protected:
sal_uInt32 m_nCount;
private:
std::atomic<oslThreadIdentifier> m_nThreadId;
std::atomic<std::thread::id> m_nThreadId;
SolarMutex(const SolarMutex&) = delete;
SolarMutex& operator=(const SolarMutex&) = delete;