include/unotools/cmdoptions.hxx       |   11 -----------
 unotools/source/config/cmdoptions.cxx |   27 +++++++++++++--------------
 2 files changed, 13 insertions(+), 25 deletions(-)

New commits:
commit 1576ef8532cf2cea2da361db9c5707f1994e65e2
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Dec 23 18:40:44 2021 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Dec 24 19:50:02 2021 +0100

    osl::Mutex->std::mutex in SvtCommandOptions
    
    Change-Id: I80eaba645351e2f3a3c67586fdced3325608633e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127413
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/include/unotools/cmdoptions.hxx b/include/unotools/cmdoptions.hxx
index d0e6792ba8b9..bb3414f8ff41 100644
--- a/include/unotools/cmdoptions.hxx
+++ b/include/unotools/cmdoptions.hxx
@@ -109,17 +109,6 @@ public:
 
     void EstablishFrameCallback(const css::uno::Reference<css::frame::XFrame>& 
xFrame);
 
-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.
-    
**-***************************************************************************************************/
-
-    UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex();
-
 private:
     std::shared_ptr<SvtCommandOptions_Impl> m_pImpl;
 
diff --git a/unotools/source/config/cmdoptions.cxx 
b/unotools/source/config/cmdoptions.cxx
index d9e061224a4a..1408f22c2480 100644
--- a/unotools/source/config/cmdoptions.cxx
+++ b/unotools/source/config/cmdoptions.cxx
@@ -84,6 +84,12 @@ class SvtCmdOptions
         CommandHashMap m_aCommandHashMap;
 };
 
+std::mutex& GetOwnStaticMutex()
+{
+    static std::mutex theCommandOptionsMutex;
+    return theCommandOptionsMutex;
+}
+
 }
 
 typedef ::std::vector< css::uno::WeakReference< css::frame::XFrame > > 
SvtFrameVector;
@@ -185,7 +191,7 @@ SvtCommandOptions_Impl::~SvtCommandOptions_Impl()
 
 void SvtCommandOptions_Impl::Notify( const Sequence< OUString >& )
 {
-    MutexGuard aGuard( SvtCommandOptions::GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
 
     Sequence< OUString >    lNames   = impl_GetPropertyNames ();
     Sequence< Any >         lValues  = GetProperties         ( lNames         
);
@@ -296,13 +302,14 @@ std::weak_ptr<SvtCommandOptions_Impl> g_pCommandOptions;
 SvtCommandOptions::SvtCommandOptions()
 {
     // Global access, must be guarded (multithreading!).
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
 
     m_pImpl = g_pCommandOptions.lock();
     if( !m_pImpl )
     {
         m_pImpl = std::make_shared<SvtCommandOptions_Impl>();
         g_pCommandOptions = m_pImpl;
+        aGuard.unlock(); // because holdConfigItem will call this constructor
         ItemHolder1::holdConfigItem(EItem::CmdOptions);
     }
 }
@@ -310,7 +317,7 @@ SvtCommandOptions::SvtCommandOptions()
 SvtCommandOptions::~SvtCommandOptions()
 {
     // Global access, must be guarded (multithreading!)
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
 
     m_pImpl.reset();
 }
@@ -319,7 +326,7 @@ SvtCommandOptions::~SvtCommandOptions()
 
 bool SvtCommandOptions::HasEntries( CmdOption eOption ) const
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->HasEntries( eOption );
 }
 
@@ -327,7 +334,7 @@ bool SvtCommandOptions::HasEntries( CmdOption eOption ) 
const
 
 bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& 
aCommandURL ) const
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->Lookup( eCmdOption, aCommandURL );
 }
 
@@ -335,16 +342,8 @@ bool SvtCommandOptions::Lookup( CmdOption eCmdOption, 
const OUString& aCommandUR
 
 void SvtCommandOptions::EstablishFrameCallback(const css::uno::Reference< 
css::frame::XFrame >& xFrame)
 {
-    MutexGuard aGuard( GetOwnStaticMutex() );
+    std::unique_lock aGuard( GetOwnStaticMutex() );
     m_pImpl->EstablishFrameCallback(xFrame);
 }
 
-//  private method
-
-Mutex& SvtCommandOptions::GetOwnStaticMutex()
-{
-    static osl::Mutex theCommandOptionsMutex;
-    return theCommandOptionsMutex;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to