include/unotools/useroptions.hxx       |    2 -
 unotools/source/config/useroptions.cxx |   34 +++++++++++++++++----------------
 2 files changed, 18 insertions(+), 18 deletions(-)

New commits:
commit ac511d90cdf9d28eb8809c30be9fa08b42ea0bd3
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Dec 23 19:42:19 2021 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Dec 24 19:10:25 2021 +0100

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

diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx
index adc5f5055d5b..d21482dcca2d 100644
--- a/include/unotools/useroptions.hxx
+++ b/include/unotools/useroptions.hxx
@@ -60,8 +60,6 @@ public:
     SvtUserOptions ();
     virtual ~SvtUserOptions () override;
 
-    static osl::Mutex& GetInitMutex ();
-
     // get the address token
     OUString GetCompany        () const;
     OUString GetFirstName      () const;
diff --git a/unotools/source/config/useroptions.cxx 
b/unotools/source/config/useroptions.cxx
index ffe01cca497c..448850fb84fc 100644
--- a/unotools/source/config/useroptions.cxx
+++ b/unotools/source/config/useroptions.cxx
@@ -259,34 +259,36 @@ bool SvtUserOptions::Impl::IsTokenReadonly (UserOptToken 
nToken) const
             beans::PropertyAttribute::READONLY);
 }
 
+static std::mutex& GetInitMutex()
+{
+    static std::mutex gMutex;
+    return gMutex;
+}
+
+
 SvtUserOptions::SvtUserOptions ()
 {
     // Global access, must be guarded (multithreading)
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
 
-    if (xSharedImpl.expired())
+    xImpl = xSharedImpl.lock();
+    if (!xImpl)
     {
         xImpl = std::make_shared<Impl>();
         xSharedImpl = xImpl;
+        aGuard.unlock(); // because holdConfigItem will call this constructor
         ItemHolder1::holdConfigItem(EItem::UserOptions);
     }
-    xImpl = xSharedImpl.lock();
     xImpl->AddListener(this);
 }
 
 SvtUserOptions::~SvtUserOptions()
 {
     // Global access, must be guarded (multithreading)
-    osl::MutexGuard aGuard( GetInitMutex() );
+    std::unique_lock aGuard( GetInitMutex() );
     xImpl->RemoveListener(this);
 }
 
-osl::Mutex& SvtUserOptions::GetInitMutex()
-{
-    static osl::Mutex gMutex;
-    return gMutex;
-}
-
 OUString SvtUserOptions::GetCompany        () const { return 
GetToken(UserOptToken::Company); }
 OUString SvtUserOptions::GetFirstName      () const { return 
GetToken(UserOptToken::FirstName); }
 OUString SvtUserOptions::GetLastName       () const { return 
GetToken(UserOptToken::LastName); }
@@ -307,37 +309,37 @@ OUString SvtUserOptions::GetEncryptionKey  () const { 
return GetToken(UserOptTok
 
 bool SvtUserOptions::IsTokenReadonly (UserOptToken nToken) const
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     return xImpl->IsTokenReadonly(nToken);
 }
 
 OUString SvtUserOptions::GetToken (UserOptToken nToken) const
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     return xImpl->GetToken(nToken);
 }
 
 void SvtUserOptions::SetToken (UserOptToken nToken, OUString const& rNewToken)
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     xImpl->SetToken(nToken, rNewToken);
 }
 
 void SvtUserOptions::SetBoolValue (UserOptToken nToken, bool bNewValue)
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     xImpl->SetBoolValue(nToken, bNewValue);
 }
 
 bool SvtUserOptions::GetEncryptToSelf() const
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     return xImpl->GetBoolValue(UserOptToken::EncryptToSelf);
 }
 
 OUString SvtUserOptions::GetFullName () const
 {
-    osl::MutexGuard aGuard(GetInitMutex());
+    std::unique_lock aGuard(GetInitMutex());
     return xImpl->GetFullName();
 }
 

Reply via email to