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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user