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/source/deployment/gui | |
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/source/deployment/gui')
-rw-r--r-- | desktop/source/deployment/gui/dp_gui_extlistbox.cxx | 118 |
1 files changed, 61 insertions, 57 deletions
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; |