comphelper/source/misc/solarmutex.cxx | 9 ++++----- include/comphelper/solarmutex.hxx | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-)
New commits: commit 1a6833a00fb7fcf04c71fcaa05dbee1f15a075d4 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Jul 1 11:36:25 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jul 4 15:42:15 2022 +0200 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.gran...@collabora.co.uk> diff --git a/comphelper/source/misc/solarmutex.cxx b/comphelper/source/misc/solarmutex.cxx index 5d1052327154..3e45ae14582d 100644 --- a/comphelper/source/misc/solarmutex.cxx +++ b/comphelper/source/misc/solarmutex.cxx @@ -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; } diff --git a/include/comphelper/solarmutex.hxx b/include/comphelper/solarmutex.hxx index 4094e08ee1f7..f9af16f1d3ad 100644 --- a/include/comphelper/solarmutex.hxx +++ b/include/comphelper/solarmutex.hxx @@ -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;