diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-04-05 14:44:34 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-07-13 12:10:29 +0200 |
commit | 1b9d48f59e8a04c3b9d829e150a59fc88084445b (patch) | |
tree | 0357ae9084d0d6111e03e550760ef64cb6312790 /vcl | |
parent | 799a590ad2c291c61084b3229a04cb51954666ca (diff) |
WIN shorten DoYield by using existing functions
This also adds an sal_uLong nCount parameter to
ImplSalYieldMutexAcquireWithWait, so it can be called like
ImplSalAcquireYieldMutex and actually uses the result from
the deferred DoYield.
Change-Id: Ie3b466ad03e7ed8c35a62f41c09d09757865364d
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/win/saldata.hxx | 2 | ||||
-rw-r--r-- | vcl/win/app/salinst.cxx | 61 |
2 files changed, 24 insertions, 39 deletions
diff --git a/vcl/inc/win/saldata.hxx b/vcl/inc/win/saldata.hxx index 367319743c94..b28f3e2c09be 100644 --- a/vcl/inc/win/saldata.hxx +++ b/vcl/inc/win/saldata.hxx @@ -171,7 +171,7 @@ bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon ); void ImplInitSalGDI(); void ImplFreeSalGDI(); -void ImplSalYieldMutexAcquireWithWait(); +void ImplSalYieldMutexAcquireWithWait( sal_uLong nCount = 1 ); bool ImplSalYieldMutexTryToAcquire(); void ImplSalYieldMutexRelease(); sal_uLong ImplSalReleaseYieldMutex(); diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx index 5ef585891e1b..1b1d0f82fee8 100644 --- a/vcl/win/app/salinst.cxx +++ b/vcl/win/app/salinst.cxx @@ -182,7 +182,7 @@ sal_uLong SalYieldMutex::GetAcquireCount( sal_uLong nThreadId ) /// note: while VCL is fully up and running (other threads started and /// before shutdown), the main thread must acquire SolarMutex only via /// this function to avoid deadlock -void ImplSalYieldMutexAcquireWithWait() +void ImplSalYieldMutexAcquireWithWait( sal_uLong nCount ) { WinSalInstance* pInst = GetSalData()->mpFirstInstance; if ( !pInst ) @@ -197,21 +197,26 @@ void ImplSalYieldMutexAcquireWithWait() // needed because if we don't reschedule, then we create deadlocks if a // Window's create/destroy is called via SendMessage() from another thread. // Have a look at the osl_waitCondition implementation for more info. - pInst->mpSalYieldMutex->m_condition.reset(); - while (!pInst->mpSalYieldMutex->tryToAcquire()) + SalYieldMutex * const pYieldMutex = pInst->mpSalYieldMutex; + osl::Condition &rCondition = pYieldMutex->m_condition; + while ( nCount ) { - // wait for SalYieldMutex::release() to set the condition - osl::Condition::Result res = pInst->mpSalYieldMutex->m_condition.wait(); - assert(osl::Condition::Result::result_ok == res); - // reset condition *before* acquiring! - pInst->mpSalYieldMutex->m_condition.reset(); + do { + // reset condition *before* acquiring! + rCondition.reset(); + if (pYieldMutex->tryToAcquire()) + break; + // wait for SalYieldMutex::release() to set the condition + osl::Condition::Result res = rCondition.wait(); + assert(osl::Condition::Result::result_ok == res); + } + while ( 1 ); + --nCount; } } else - { // If this is not the main thread, call acquire directly. - pInst->mpSalYieldMutex->acquire(); - } + ImplSalAcquireYieldMutex( nCount ); } bool ImplSalYieldMutexTryToAcquire() @@ -597,17 +602,8 @@ bool WinSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong bool bDidWork = false; // NOTE: if nReleased != 0 this will be called without SolarMutex // so don't do anything dangerous before releasing it here - SalYieldMutex* pYieldMutex = mpSalYieldMutex; - DWORD nCurThreadId = GetCurrentThreadId(); sal_uLong const nCount = (nReleased != 0) - ? nReleased - : pYieldMutex->GetAcquireCount(nCurThreadId); - sal_uLong n = (nReleased != 0) ? 0 : nCount; - while ( n ) - { - pYieldMutex->release(); - n--; - } + ? nReleased : ImplSalReleaseYieldMutex(); if ( !IsMainThread() ) { // #97739# A SendMessage call blocks until the called thread (here: the main thread) @@ -621,31 +617,20 @@ bool WinSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong // #i18883# only sleep if potential deadlock scenario, ie, when a dialog is open if( ImplGetSVData()->maAppData.mnModalMode ) - Sleep(1); + SwitchToThread(); else - SendMessageW( mhComWnd, SAL_MSG_THREADYIELD, (WPARAM)bWait, (LPARAM)bHandleAllCurrentEvents ); + bDidWork = SendMessageW( mhComWnd, SAL_MSG_THREADYIELD, (WPARAM)bWait, (LPARAM)bHandleAllCurrentEvents ); - n = nCount; - while ( n ) - { - pYieldMutex->acquire(); - n--; - } + ImplSalAcquireYieldMutex( nCount ); } else { if (nReleased == 0) // tdf#99383 ReAcquireSolarMutex shouldn't Yield - { bDidWork = ImplSalYield( bWait, bHandleAllCurrentEvents ); - } - n = nCount; - while ( n ) - { - ImplSalYieldMutexAcquireWithWait(); - n--; - } + ImplSalYieldMutexAcquireWithWait( nCount ); } + return bDidWork; } @@ -656,7 +641,7 @@ LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, i switch ( nMsg ) { case SAL_MSG_THREADYIELD: - ImplSalYield( (bool)wParam, (bool)lParam ); + nRet = static_cast<LRESULT>(ImplSalYield( (bool)wParam, (bool)lParam )); rDef = FALSE; break; case SAL_MSG_STARTTIMER: |