diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-08-15 08:05:51 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-09-19 09:25:14 +0200 |
commit | 3840aede596e6fc24f7ed7df9100fb028134aac6 (patch) | |
tree | 74d1d5efa3b2ad5448181fc185faf226aed192e4 /vcl/osx/salinst.cxx | |
parent | 10b49dfb3996f99dec8dd0d2ffae2aef4022f395 (diff) |
Unify SolarMutex implementations
All backends implement the SolarMutex in mostly the same way.
So this consolidates this code into a GenericSolarMutex.
We still need the abstract SolarMutex class for the fake AKA
fascade implementation in dbaccess.
The patch also replaces various places of direct mutex usage with
either SolarMutexGuard or SolarMutexReleaser objects.
Change-Id: Ia0146dd6c51a3b9a513cc6af34a66def58aad831
Reviewed-on: https://gerrit.libreoffice.org/42325
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/osx/salinst.cxx')
-rw-r--r-- | vcl/osx/salinst.cxx | 106 |
1 files changed, 15 insertions, 91 deletions
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx index e16e73945c2d..aa274e8292f3 100644 --- a/vcl/osx/salinst.cxx +++ b/vcl/osx/salinst.cxx @@ -259,41 +259,20 @@ void InitSalMain() SalYieldMutex::SalYieldMutex() { - mnCount = 0; - mnThreadId = 0; } -void SalYieldMutex::acquire() +SalYieldMutex::~SalYieldMutex() { - m_mutex.acquire(); - mnThreadId = osl::Thread::getCurrentIdentifier(); - mnCount++; } -void SalYieldMutex::release() +void SalYieldMutex::doAcquire( sal_uInt32 nLockCount ) { - if ( mnThreadId == osl::Thread::getCurrentIdentifier() ) - { - if ( mnCount == 1 ) - { - // TODO: add OpenGLContext::prepareForYield with vcl OpenGL support - mnThreadId = 0; - } - mnCount--; - } - m_mutex.release(); + comphelper::GenericSolarMutex::doAcquire( nLockCount ); } -bool SalYieldMutex::tryToAcquire() +sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll ) { - if ( m_mutex.tryToAcquire() ) - { - mnThreadId = osl::Thread::getCurrentIdentifier(); - mnCount++; - return true; - } - else - return false; + return comphelper::GenericSolarMutex::doRelease( bUnlockAll ); } // some convenience functions regarding the yield mutex, aka solar mutex @@ -351,7 +330,6 @@ AquaSalInstance::AquaSalInstance() { mpSalYieldMutex = new SalYieldMutex; mpSalYieldMutex->acquire(); - ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex ); maMainThread = osl::Thread::getCurrentIdentifier(); mbWaitingYield = false; mnActivePrintJobs = 0; @@ -359,7 +337,6 @@ AquaSalInstance::AquaSalInstance() AquaSalInstance::~AquaSalInstance() { - ::comphelper::SolarMutex::setSolarMutex( nullptr ); mpSalYieldMutex->release(); delete mpSalYieldMutex; } @@ -386,47 +363,14 @@ comphelper::SolarMutex* AquaSalInstance::GetYieldMutex() return mpSalYieldMutex; } -sal_uLong AquaSalInstance::ReleaseYieldMutex() -{ - SalYieldMutex* pYieldMutex = mpSalYieldMutex; - if ( pYieldMutex->GetThreadId() == - osl::Thread::getCurrentIdentifier() ) - { - sal_uLong nCount = pYieldMutex->GetAcquireCount(); - sal_uLong n = nCount; - while ( n ) - { - pYieldMutex->release(); - n--; - } - - return nCount; - } - else - return 0; -} - -void AquaSalInstance::AcquireYieldMutex( sal_uLong nCount ) +sal_uInt32 AquaSalInstance::ReleaseYieldMutex( bool bUnlockAll ) { - SalYieldMutex* pYieldMutex = mpSalYieldMutex; - while ( nCount ) - { - pYieldMutex->acquire(); - nCount--; - } + return mpSalYieldMutex->release( bUnlockAll ); } -bool AquaSalInstance::CheckYieldMutex() +void AquaSalInstance::AcquireYieldMutex( sal_uInt32 nCount ) { - bool bRet = true; - - SalYieldMutex* pYieldMutex = mpSalYieldMutex; - if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier()) - { - bRet = false; - } - - return bRet; + mpSalYieldMutex->acquire( nCount ); } bool AquaSalInstance::IsMainThread() const @@ -596,7 +540,7 @@ bool AquaSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLon NSEvent* pEvent = nil; do { - sal_uLong nCount = ReleaseYieldMutex(); + SolarMutexReleaser aReleaser; SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'NSAnyEventMask' is deprecated: first deprecated in macOS 10.12 @@ -610,15 +554,15 @@ SAL_WNODEPRECATED_DECLARATIONS_POP [NSApp sendEvent: pEvent]; bHadEvent = true; } - [NSApp updateWindows]; - AcquireYieldMutex( nCount ); - } while( bHandleAllCurrentEvents && pEvent ); + [NSApp updateWindows]; + } + while( bHandleAllCurrentEvents && pEvent ); // if we had no event yet, wait for one if requested if( bWait && ! bHadEvent ) { - sal_uLong nCount = ReleaseYieldMutex(); + SolarMutexReleaser aReleaser; NSDate* pDt = AquaSalTimer::pRunningTimer ? [AquaSalTimer::pRunningTimer fireDate] : [NSDate distantFuture]; SAL_WNODEPRECATED_DECLARATIONS_PUSH @@ -631,8 +575,6 @@ SAL_WNODEPRECATED_DECLARATIONS_POP if( pEvent ) [NSApp sendEvent: pEvent]; [NSApp updateWindows]; - - AcquireYieldMutex( nCount ); } mbWaitingYield = bOldWaitingYield; @@ -656,9 +598,8 @@ SAL_WNODEPRECATED_DECLARATIONS_POP // has dispatched an event, cop out at 200 ms maWaitingYieldCond.reset(); TimeValue aVal = { 0, 200000000 }; - sal_uLong nCount = ReleaseYieldMutex(); + SolarMutexReleaser aReleaser; maWaitingYieldCond.wait( &aVal ); - AcquireYieldMutex( nCount ); } // we get some apple events way too early @@ -982,23 +923,6 @@ OUString AquaSalInstance::getOSVersion() return aVersion; } -// YieldMutexReleaser -YieldMutexReleaser::YieldMutexReleaser() : mnCount( 0 ) -{ - SalData* pSalData = GetSalData(); - if( ! pSalData->mpFirstInstance->IsMainThread() ) - { - SalData::ensureThreadAutoreleasePool(); - mnCount = pSalData->mpFirstInstance->ReleaseYieldMutex(); - } -} - -YieldMutexReleaser::~YieldMutexReleaser() -{ - if( mnCount != 0 ) - GetSalData()->mpFirstInstance->AcquireYieldMutex( mnCount ); -} - CGImageRef CreateCGImage( const Image& rImage ) { BitmapEx aBmpEx( rImage.GetBitmapEx() ); |