diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-07 11:48:47 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-07 17:53:04 +0200 |
commit | 5a824268dfdd48c00f656b767b48cd12ccbdaabb (patch) | |
tree | a25f4afd3ca49cff41fc44559aedea70c82e6c7e /desktop | |
parent | a6186a678cd9f67359da885606b3c3983f6bdc74 (diff) |
Don't use resettable/clearable guard where plain guard is enough
Also use scope where possible. This allows to limit guard scope at
language level; visualises the scope clearly; and helps avoiding
errors like fixed in commit 61e4437c857854b331fa01da6f39b2b3b58a800b.
Change-Id: Ifeca96e2df8e8a0897770d9546b2536806275f41
Reviewed-on: https://gerrit.libreoffice.org/70376
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/app/dispatchwatcher.cxx | 9 | ||||
-rw-r--r-- | desktop/source/deployment/gui/dp_gui_extlistbox.cxx | 118 | ||||
-rw-r--r-- | desktop/source/offacc/acceptor.cxx | 2 | ||||
-rw-r--r-- | desktop/source/splash/splash.cxx | 2 |
4 files changed, 68 insertions, 63 deletions
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 872d98333982..5393b07e130d 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -406,7 +406,7 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest if( xDispatcher.is() ) { { - ::osl::ClearableMutexGuard aGuard(m_mutex); + osl::MutexGuard aGuard(m_mutex); // Remember request so we can find it in statusChanged! m_nRequestCount++; } @@ -754,9 +754,10 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest xDisp->dispatchWithNotification( aDispatche.aURL, aArgs, this ); else { - ::osl::ClearableMutexGuard aGuard(m_mutex); - m_nRequestCount--; - aGuard.clear(); + { + osl::MutexGuard aGuard(m_mutex); + m_nRequestCount--; + } xDispatch->dispatch( aDispatche.aURL, aArgs ); } } diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx index c37ec6945d93..6e13917875c8 100644 --- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx +++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx @@ -920,38 +920,39 @@ void ExtensionBox_Impl::addEntry( const uno::Reference< deployment::XPackage > & if ( pEntry->m_sTitle.isEmpty() ) return; - ::osl::ClearableMutexGuard guard(m_entriesMutex); - if ( m_vEntries.empty() ) - { - addEventListenerOnce(xPackage); - m_vEntries.push_back( pEntry ); - } - else { - if ( !FindEntryPos( pEntry, 0, m_vEntries.size()-1, nPos ) ) + osl::MutexGuard guard(m_entriesMutex); + if (m_vEntries.empty()) { addEventListenerOnce(xPackage); - m_vEntries.insert( m_vEntries.begin()+nPos, pEntry ); + m_vEntries.push_back(pEntry); } - else if ( !m_bInCheckMode ) + else { - OSL_FAIL( "ExtensionBox_Impl::addEntry(): Will not add duplicate entries" ); + if (!FindEntryPos(pEntry, 0, m_vEntries.size() - 1, nPos)) + { + addEventListenerOnce(xPackage); + m_vEntries.insert(m_vEntries.begin() + nPos, pEntry); + } + else if (!m_bInCheckMode) + { + OSL_FAIL("ExtensionBox_Impl::addEntry(): Will not add duplicate entries"); + } } - } - pEntry->m_bHasOptions = m_pManager->supportsOptions( xPackage ); - pEntry->m_bUser = (xPackage->getRepositoryName() == USER_PACKAGE_MANAGER); - pEntry->m_bShared = (xPackage->getRepositoryName() == SHARED_PACKAGE_MANAGER); - pEntry->m_bNew = m_bInCheckMode; - pEntry->m_bMissingLic = bLicenseMissing; + pEntry->m_bHasOptions = m_pManager->supportsOptions(xPackage); + pEntry->m_bUser = (xPackage->getRepositoryName() == USER_PACKAGE_MANAGER); + pEntry->m_bShared = (xPackage->getRepositoryName() == SHARED_PACKAGE_MANAGER); + pEntry->m_bNew = m_bInCheckMode; + pEntry->m_bMissingLic = bLicenseMissing; - if ( bLicenseMissing ) - pEntry->m_sErrorText = DpResId( RID_STR_ERROR_MISSING_LICENSE ); + if (bLicenseMissing) + pEntry->m_sErrorText = DpResId(RID_STR_ERROR_MISSING_LICENSE); - //access to m_nActive must be guarded - if ( !m_bInCheckMode && m_bHasActive && ( m_nActive >= nPos ) ) - m_nActive += 1; - guard.clear(); + //access to m_nActive must be guarded + if (!m_bInCheckMode && m_bHasActive && (m_nActive >= nPos)) + m_nActive += 1; + } if ( IsReallyVisible() ) Invalidate(); @@ -1087,47 +1088,50 @@ void ExtensionBox_Impl::checkEntries() long nPos = 0; bool bNeedsUpdate = false; - ::osl::ClearableMutexGuard guard(m_entriesMutex); - auto iIndex = m_vEntries.begin(); - while ( iIndex != m_vEntries.end() ) { - if ( !(*iIndex)->m_bChecked ) + osl::MutexGuard guard(m_entriesMutex); + auto iIndex = m_vEntries.begin(); + while (iIndex != m_vEntries.end()) { - (*iIndex)->m_bChecked = true; - bNeedsUpdate = true; - nPos = iIndex-m_vEntries.begin(); - if ( (*iIndex)->m_bNew ) - { // add entry to list and correct active pos - if ( nNewPos == - 1) - nNewPos = nPos; - if ( nPos <= m_nActive ) - m_nActive += 1; - ++iIndex; - } - else - { // remove entry from list - if (nPos < nNewPos) { - --nNewPos; - } - if (nPos < nChangedActivePos) { - --nChangedActivePos; + if (!(*iIndex)->m_bChecked) + { + (*iIndex)->m_bChecked = true; + bNeedsUpdate = true; + nPos = iIndex - m_vEntries.begin(); + if ((*iIndex)->m_bNew) + { // add entry to list and correct active pos + if (nNewPos == -1) + nNewPos = nPos; + if (nPos <= m_nActive) + m_nActive += 1; + ++iIndex; } - if ( nPos < m_nActive ) - m_nActive -= 1; - else if ( nPos == m_nActive ) - { - nChangedActivePos = nPos; - m_nActive = -1; - m_bHasActive = false; + else + { // remove entry from list + if (nPos < nNewPos) + { + --nNewPos; + } + if (nPos < nChangedActivePos) + { + --nChangedActivePos; + } + if (nPos < m_nActive) + m_nActive -= 1; + else if (nPos == m_nActive) + { + nChangedActivePos = nPos; + m_nActive = -1; + m_bHasActive = false; + } + m_vRemovedEntries.push_back(*iIndex); + iIndex = m_vEntries.erase(iIndex); } - m_vRemovedEntries.push_back( *iIndex ); - iIndex = m_vEntries.erase( iIndex ); } + else + ++iIndex; } - else - ++iIndex; } - guard.clear(); m_bInCheckMode = false; diff --git a/desktop/source/offacc/acceptor.cxx b/desktop/source/offacc/acceptor.cxx index d806ea7471e6..894f20623e78 100644 --- a/desktop/source/offacc/acceptor.cxx +++ b/desktop/source/offacc/acceptor.cxx @@ -134,7 +134,7 @@ void Acceptor::run() void Acceptor::initialize( const Sequence<Any>& aArguments ) { // prevent multiple initialization - osl::ClearableMutexGuard aGuard( m_aMutex ); + osl::MutexGuard aGuard( m_aMutex ); SAL_INFO( "desktop.offacc", "Acceptor::initialize()" ); bool bOk = false; diff --git a/desktop/source/splash/splash.cxx b/desktop/source/splash/splash.cxx index 195539060b81..64af4ce7fd6a 100644 --- a/desktop/source/splash/splash.cxx +++ b/desktop/source/splash/splash.cxx @@ -250,7 +250,7 @@ void SAL_CALL SplashScreen::setValue(sal_Int32 nValue) void SAL_CALL SplashScreen::initialize( const css::uno::Sequence< css::uno::Any>& aArguments ) { - ::osl::ClearableMutexGuard aGuard( _aMutex ); + osl::MutexGuard aGuard( _aMutex ); if (aArguments.getLength() > 0) { aArguments[0] >>= _bVisible; |