include/unotools/eventcfg.hxx       |    1 
 unotools/source/config/eventcfg.cxx |   37 ++++++++++++++++--------------------
 2 files changed, 17 insertions(+), 21 deletions(-)

New commits:
commit f75b742997c119ccb081faa7e63ce04b8e88912c
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon May 9 18:06:54 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 10 19:26:20 2022 +0200

    osl::Mutex->std::mutex in GlobalEventConfig
    
    Change-Id: Id54f9f15547010c9df640e406d36fb09febac4cd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134089
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/unotools/eventcfg.hxx b/include/unotools/eventcfg.hxx
index 660ec91b02f0..5999d0bc1ea3 100644
--- a/include/unotools/eventcfg.hxx
+++ b/include/unotools/eventcfg.hxx
@@ -65,7 +65,6 @@ class UNOTOOLS_DLLPUBLIC GlobalEventConfig final :
     public:
         GlobalEventConfig( );
         virtual ~GlobalEventConfig( ) override;
-        static ::osl::Mutex& GetOwnStaticMutex();
 
         css::uno::Reference< css::container::XNameReplace > SAL_CALL 
getEvents(  ) override;
         void SAL_CALL replaceByName( const OUString& aName, const 
css::uno::Any& aElement ) override;
diff --git a/unotools/source/config/eventcfg.cxx 
b/unotools/source/config/eventcfg.cxx
index 197546f5502b..0c0f87ed4624 100644
--- a/unotools/source/config/eventcfg.cxx
+++ b/unotools/source/config/eventcfg.cxx
@@ -81,6 +81,12 @@ static o3tl::enumarray<GlobalEventId, const char*> 
pEventAsciiNames =
 typedef std::unordered_map< OUString, OUString > EventBindingHash;
 typedef o3tl::enumarray< GlobalEventId, OUString > SupportedEventsVector;
 
+static std::mutex& GetOwnStaticMutex()
+{
+    static std::mutex INSTANCE;
+    return INSTANCE;
+}
+
 class GlobalEventConfig_Impl : public utl::ConfigItem
 {
 private:
@@ -150,7 +156,7 @@ OUString const & GlobalEventConfig_Impl::GetEventName( 
GlobalEventId nIndex ) co
 
 void GlobalEventConfig_Impl::Notify( const Sequence< OUString >& )
 {
-    MutexGuard aGuard( GlobalEventConfig::GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
 
     initBindingInfo();
 }
@@ -295,13 +301,14 @@ sal_Int32                   
GlobalEventConfig::m_nRefCount      = 0;
 GlobalEventConfig::GlobalEventConfig()
 {
     // Global access, must be guarded (multithreading!).
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     // Increase our refcount ...
     ++m_nRefCount;
     // ... and initialize our data container only if it not already exist!
     if( m_pImpl == nullptr )
     {
         m_pImpl = new GlobalEventConfig_Impl;
+        aGuard.unlock();
         ItemHolder1::holdConfigItem(EItem::EventConfig);
     }
 }
@@ -309,7 +316,7 @@ GlobalEventConfig::GlobalEventConfig()
 GlobalEventConfig::~GlobalEventConfig()
 {
     // Global access, must be guarded (multithreading!)
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     // Decrease our refcount.
     --m_nRefCount;
     // If last instance was deleted ...
@@ -323,52 +330,42 @@ GlobalEventConfig::~GlobalEventConfig()
 
 Reference< container::XNameReplace > SAL_CALL GlobalEventConfig::getEvents()
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     Reference< container::XNameReplace > ret(this);
     return ret;
 }
 
 void SAL_CALL GlobalEventConfig::replaceByName( const OUString& aName, const 
Any& aElement )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     m_pImpl->replaceByName( aName, aElement );
 }
 Any SAL_CALL GlobalEventConfig::getByName( const OUString& aName )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->getByName( aName );
 }
 Sequence< OUString > SAL_CALL GlobalEventConfig::getElementNames(  )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->getElementNames( );
 }
 sal_Bool SAL_CALL GlobalEventConfig::hasByName( const OUString& aName )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->hasByName( aName );
 }
 Type SAL_CALL GlobalEventConfig::getElementType(  )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return GlobalEventConfig_Impl::getElementType( );
 }
 sal_Bool SAL_CALL GlobalEventConfig::hasElements(  )
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->hasElements( );
 }
 
-namespace
-{
-    class theGlobalEventConfigMutex : public rtl::Static<osl::Mutex, 
theGlobalEventConfigMutex>{};
-}
-
-Mutex& GlobalEventConfig::GetOwnStaticMutex()
-{
-    return theGlobalEventConfigMutex::get();
-}
-
 OUString GlobalEventConfig::GetEventName( GlobalEventId nIndex )
 {
     if (utl::ConfigManager::IsFuzzing())

Reply via email to