From bf44ea9d2daea4a57d7add7d2d81c8309d659bb2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 20 Dec 2021 21:08:31 +0200 Subject: osl::Mutex->std::mutex in Svt*Options Change-Id: I329849310f289e0fe7a886bbf3855f8d569767c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127830 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/svtools/miscopt.hxx | 13 ------------- include/svtools/slidesorterbaropt.hxx | 12 ------------ svtools/source/config/accessibilityoptions.cxx | 10 ++++++---- svtools/source/config/colorcfg.cxx | 11 ++++++----- svtools/source/config/extcolorcfg.cxx | 10 +++++----- svtools/source/config/miscopt.cxx | 19 +++++++++++-------- svtools/source/config/slidesorterbaropt.cxx | 18 ++++++++++-------- 7 files changed, 38 insertions(+), 55 deletions(-) diff --git a/include/svtools/miscopt.hxx b/include/svtools/miscopt.hxx index 82b15340dc63..190de033c129 100644 --- a/include/svtools/miscopt.hxx +++ b/include/svtools/miscopt.hxx @@ -24,7 +24,6 @@ #include #include -namespace osl { class Mutex; } template class Link; class LinkParamNone; @@ -63,18 +62,6 @@ class SVT_DLLPUBLIC SvtMiscOptions final : public utl::detail::Options void SetIconTheme(const OUString&); bool IconThemeWasSetAutomatically() const; - private: - - /*-**************************************************************************************************** - @short return a reference to a static mutex - @descr These class is partially threadsafe (for de-/initialization only). - All access methods aren't safe! - We create a static mutex only for one ime and use at different times. - @return A reference to a static mutex member. - *//*-*****************************************************************************************************/ - - SVT_DLLPRIVATE static ::osl::Mutex& GetInitMutex(); - private: std::shared_ptr m_pImpl; diff --git a/include/svtools/slidesorterbaropt.hxx b/include/svtools/slidesorterbaropt.hxx index 4456a857513b..9250838fafff 100644 --- a/include/svtools/slidesorterbaropt.hxx +++ b/include/svtools/slidesorterbaropt.hxx @@ -23,8 +23,6 @@ #include #include -namespace osl { class Mutex; } - /** forward declaration to our private date container implementation We use these class as internal member to support small memory requirements. @@ -57,16 +55,6 @@ class SVT_DLLPUBLIC SvtSlideSorterBarOptions final : public utl::detail::Options void SetVisibleDrawView( bool bVisible ); - private: - /** return a reference to a static mutex - - These class is partially threadsafe (for de-/initialization only). - All access methods aren't safe! - We create a static mutex only for one ime and use at different times. - - \return A reference to a static mutex member.*/ - SVT_DLLPRIVATE static ::osl::Mutex& GetInitMutex(); - private: std::shared_ptr m_pImpl; }; diff --git a/svtools/source/config/accessibilityoptions.cxx b/svtools/source/config/accessibilityoptions.cxx index 05c113478402..4922326fa0f0 100644 --- a/svtools/source/config/accessibilityoptions.cxx +++ b/svtools/source/config/accessibilityoptions.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include "itemholder2.hxx" @@ -70,9 +71,9 @@ sal_Int32 SvtAccessibilityOptions::sm_nAccessibilityRefCount namespace { - ::osl::Mutex& SingletonMutex() + std::mutex& SingletonMutex() { - static ::osl::Mutex SINGLETON; + static std::mutex SINGLETON; return SINGLETON; } } @@ -337,10 +338,11 @@ SvtAccessibilityOptions::SvtAccessibilityOptions() { if (!utl::ConfigManager::IsFuzzing()) { - ::osl::MutexGuard aGuard( SingletonMutex() ); + std::unique_lock aGuard( SingletonMutex() ); if(!sm_pSingleImplConfig) { sm_pSingleImplConfig = new SvtAccessibilityOptions_Impl; + aGuard.unlock(); // because holdConfigItem will call this constructor svtools::ItemHolder2::holdConfigItem(EItem::AccessibilityOptions); } ++sm_nAccessibilityRefCount; @@ -351,7 +353,7 @@ SvtAccessibilityOptions::SvtAccessibilityOptions() SvtAccessibilityOptions::~SvtAccessibilityOptions() { //EndListening( *sm_pSingleImplConfig, sal_True ); - ::osl::MutexGuard aGuard( SingletonMutex() ); + std::unique_lock aGuard( SingletonMutex() ); if( !--sm_nAccessibilityRefCount ) { //if( sm_pSingleImplConfig->IsModified() ) diff --git a/svtools/source/config/colorcfg.cxx b/svtools/source/config/colorcfg.cxx index f72736afe6cb..3bbd37f6c9ce 100644 --- a/svtools/source/config/colorcfg.cxx +++ b/svtools/source/config/colorcfg.cxx @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include "itemholder2.hxx" @@ -53,9 +53,9 @@ namespace svtools static sal_Int32 nColorRefCount_Impl = 0; namespace { - ::osl::Mutex& ColorMutex_Impl() + std::mutex& ColorMutex_Impl() { - static ::osl::Mutex SINGLETON; + static std::mutex SINGLETON; return SINGLETON; } } @@ -378,10 +378,11 @@ ColorConfig::ColorConfig() { if (utl::ConfigManager::IsFuzzing()) return; - ::osl::MutexGuard aGuard( ColorMutex_Impl() ); + std::unique_lock aGuard( ColorMutex_Impl() ); if ( !m_pImpl ) { m_pImpl = new ColorConfig_Impl; + aGuard.unlock(); // because holdConfigItem will call this constructor svtools::ItemHolder2::holdConfigItem(EItem::ColorConfig); } ++nColorRefCount_Impl; @@ -392,7 +393,7 @@ ColorConfig::~ColorConfig() { if (utl::ConfigManager::IsFuzzing()) return; - ::osl::MutexGuard aGuard( ColorMutex_Impl() ); + std::unique_lock aGuard( ColorMutex_Impl() ); m_pImpl->RemoveListener(this); if(!--nColorRefCount_Impl) { diff --git a/svtools/source/config/extcolorcfg.cxx b/svtools/source/config/extcolorcfg.cxx index bdeda2d4e8b9..2ad876b110f1 100644 --- a/svtools/source/config/extcolorcfg.cxx +++ b/svtools/source/config/extcolorcfg.cxx @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -50,9 +50,9 @@ namespace svtools static sal_Int32 nExtendedColorRefCount_Impl = 0; namespace { - ::osl::Mutex& ColorMutex_Impl() + std::mutex& ColorMutex_Impl() { - static ::osl::Mutex SINGLETON; + static std::mutex SINGLETON; return SINGLETON; } } @@ -508,7 +508,7 @@ IMPL_LINK( ExtendedColorConfig_Impl, DataChangedEventListener, VclSimpleEvent&, ExtendedColorConfig::ExtendedColorConfig() { - ::osl::MutexGuard aGuard( ColorMutex_Impl() ); + std::unique_lock aGuard( ColorMutex_Impl() ); if ( !m_pImpl ) m_pImpl = new ExtendedColorConfig_Impl; ++nExtendedColorRefCount_Impl; @@ -517,7 +517,7 @@ ExtendedColorConfig::ExtendedColorConfig() ExtendedColorConfig::~ExtendedColorConfig() { - ::osl::MutexGuard aGuard( ColorMutex_Impl() ); + std::unique_lock aGuard( ColorMutex_Impl() ); EndListening( *m_pImpl); if(!--nExtendedColorRefCount_Impl) { diff --git a/svtools/source/config/miscopt.cxx b/svtools/source/config/miscopt.cxx index 9c154b92dbc4..2462a5804659 100644 --- a/svtools/source/config/miscopt.cxx +++ b/svtools/source/config/miscopt.cxx @@ -32,6 +32,7 @@ #include #include +#include #include using namespace ::utl ; @@ -47,6 +48,13 @@ constexpr OUStringLiteral PROPERTYNAME_SYMBOLSET = u"SymbolSet"; constexpr OUStringLiteral PROPERTYNAME_ICONTHEME = u"SymbolStyle"; #define PROPERTYHANDLE_SYMBOLSTYLE 1 +static std::mutex & GetInitMutex() +{ + static std::mutex theSvtMiscOptionsMutex; + return theSvtMiscOptionsMutex; +} + + class SvtMiscOptions_Impl : public ConfigItem { private: @@ -363,13 +371,14 @@ std::weak_ptr g_pMiscOptions; SvtMiscOptions::SvtMiscOptions() { // Global access, must be guarded (multithreading!). - MutexGuard aGuard( GetInitMutex() ); + std::unique_lock aGuard( GetInitMutex() ); m_pImpl = g_pMiscOptions.lock(); if( !m_pImpl ) { m_pImpl = std::make_shared(); g_pMiscOptions = m_pImpl; + aGuard.unlock(); // because holdConfigItem will call this constructor svtools::ItemHolder2::holdConfigItem(EItem::MiscOptions); } } @@ -377,7 +386,7 @@ SvtMiscOptions::SvtMiscOptions() SvtMiscOptions::~SvtMiscOptions() { // Global access, must be guarded (multithreading!) - MutexGuard aGuard( GetInitMutex() ); + std::unique_lock aGuard( GetInitMutex() ); m_pImpl.reset(); } @@ -428,12 +437,6 @@ void SvtMiscOptions::SetIconTheme(const OUString& iconTheme) m_pImpl->SetIconTheme(iconTheme, SvtMiscOptions_Impl::SetModifiedFlag::SET); } -Mutex & SvtMiscOptions::GetInitMutex() -{ - static osl::Mutex theSvtMiscOptionsMutex; - return theSvtMiscOptionsMutex; -} - void SvtMiscOptions::AddListenerLink( const Link& rLink ) { m_pImpl->AddListenerLink( rLink ); diff --git a/svtools/source/config/slidesorterbaropt.cxx b/svtools/source/config/slidesorterbaropt.cxx index 22b5b6b5e768..784e0894ef27 100644 --- a/svtools/source/config/slidesorterbaropt.cxx +++ b/svtools/source/config/slidesorterbaropt.cxx @@ -26,6 +26,7 @@ #include #include +#include using namespace ::utl; using namespace ::osl; @@ -47,6 +48,13 @@ constexpr OUStringLiteral PROPERTYNAME_VISIBLE_SLIDESORTERVIEW = u"SlideSorterVi constexpr OUStringLiteral PROPERTYNAME_VISIBLE_DRAWVIEW = u"DrawView"; #define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5 +static std::mutex & GetInitMutex() +{ + static std::mutex theSvtSlideSorterBarOptionsMutex; + return theSvtSlideSorterBarOptionsMutex; +} + + class SvtSlideSorterBarOptions_Impl : public ConfigItem { Sequence< OUString > m_seqPropertyNames; @@ -335,7 +343,7 @@ namespace { SvtSlideSorterBarOptions::SvtSlideSorterBarOptions() { // Global access, must be guarded (multithreading!). - MutexGuard aGuard( GetInitMutex() ); + std::unique_lock aGuard( GetInitMutex() ); m_pImpl = g_pSlideSorterBarOptions.lock(); if( !m_pImpl ) @@ -348,7 +356,7 @@ SvtSlideSorterBarOptions::SvtSlideSorterBarOptions() SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions() { // Global access, must be guarded (multithreading!) - MutexGuard aGuard( GetInitMutex() ); + std::unique_lock aGuard( GetInitMutex() ); m_pImpl.reset(); } @@ -414,10 +422,4 @@ void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible) m_pImpl->SetVisibleDrawView( bVisible ); } -Mutex & SvtSlideSorterBarOptions::GetInitMutex() -{ - static osl::Mutex theSvtSlideSorterBarOptionsMutex; - return theSvtSlideSorterBarOptionsMutex; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3