From 5a824268dfdd48c00f656b767b48cd12ccbdaabb Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 7 Apr 2019 11:48:47 +0300 Subject: 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 --- framework/source/loadenv/loadenv.cxx | 71 +++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'framework/source/loadenv') diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 0be9ad70e82e..a5b2f36f38e2 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -344,19 +344,20 @@ void LoadEnv::initializeUIDefaults( const css::uno::Reference< css::uno::XCompon void LoadEnv::startLoading() { // SAFE -> - osl::ClearableMutexGuard aReadLock(m_mutex); - - // Handle still running processes! - if (m_xAsynchronousJob.is()) - throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING); + { + osl::MutexGuard aReadLock(m_mutex); - // content can not be loaded or handled - // check "classifyContent()" failed before ... - if (m_eContentType == E_UNSUPPORTED_CONTENT) - throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT, "from LoadEnv::startLoading"); + // Handle still running processes! + if (m_xAsynchronousJob.is()) + throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING); + // content can not be loaded or handled + // check "classifyContent()" failed before ... + if (m_eContentType == E_UNSUPPORTED_CONTENT) + throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT, + "from LoadEnv::startLoading"); + } // <- SAFE - aReadLock.clear(); // detect its type/filter etc. // These information will be available by the @@ -406,10 +407,11 @@ bool LoadEnv::waitWhileLoading(sal_uInt32 nTimeout) while(true) { // SAFE -> ------------------------------ - osl::ClearableMutexGuard aReadLock1(m_mutex); - if (!m_xAsynchronousJob.is()) - break; - aReadLock1.clear(); + { + osl::MutexGuard aReadLock1(m_mutex); + if (!m_xAsynchronousJob.is()) + break; + } // <- SAFE ------------------------------ Application::Yield(); @@ -1520,14 +1522,15 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget() } // SAFE -> .................................. - osl::ClearableMutexGuard aWriteLock(m_mutex); + { + osl::MutexGuard aWriteLock(m_mutex); - css::uno::Reference< css::document::XActionLockable > xLock(xTask, css::uno::UNO_QUERY); - if (!m_aTargetLock.setResource(xLock)) - return css::uno::Reference< css::frame::XFrame >(); + css::uno::Reference< css::document::XActionLockable > xLock(xTask, css::uno::UNO_QUERY); + if (!m_aTargetLock.setResource(xLock)) + return css::uno::Reference< css::frame::XFrame >(); - m_bReactivateControllerOnError = bReactivateOldControllerOnError; - aWriteLock.clear(); + m_bReactivateControllerOnError = bReactivateOldControllerOnError; + } // <- SAFE .................................. // bring it to front ... @@ -1705,24 +1708,24 @@ void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::aw return; // SOLAR SAFE -> - SolarMutexClearableGuard aSolarGuard1; - - VclPtr pWindow = VCLUnoHelper::GetWindow(xWindow); - if (!pWindow) - return; + { + SolarMutexGuard aSolarGuard1; - bool bSystemWindow = pWindow->IsSystemWindow(); - bool bWorkWindow = (pWindow->GetType() == WindowType::WORKWINDOW); + VclPtr pWindow = VCLUnoHelper::GetWindow(xWindow); + if (!pWindow) + return; - if (!bSystemWindow && !bWorkWindow) - return; + bool bSystemWindow = pWindow->IsSystemWindow(); + bool bWorkWindow = (pWindow->GetType() == WindowType::WORKWINDOW); - // don't overwrite this special state! - WorkWindow* pWorkWindow = static_cast(pWindow.get()); - if (pWorkWindow->IsMinimized()) - return; + if (!bSystemWindow && !bWorkWindow) + return; - aSolarGuard1.clear(); + // don't overwrite this special state! + WorkWindow* pWorkWindow = static_cast(pWindow.get()); + if (pWorkWindow->IsMinimized()) + return; + } // <- SOLAR SAFE // SAFE -> -- cgit