toolkit/source/controls/formattedcontrol.cxx |   46 +++++++++------------------
 1 file changed, 17 insertions(+), 29 deletions(-)

New commits:
commit 1082943bd8ab8174f0256f41b0d417950060e240
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Aug 3 20:40:26 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 4 08:40:47 2021 +0200

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

diff --git a/toolkit/source/controls/formattedcontrol.cxx 
b/toolkit/source/controls/formattedcontrol.cxx
index d2acd9c2e17d..2a24c23c53b7 100644
--- a/toolkit/source/controls/formattedcontrol.cxx
+++ b/toolkit/source/controls/formattedcontrol.cxx
@@ -31,6 +31,7 @@
 #include <osl/diagnose.h>
 
 #include <helper/unopropertyarrayhelper.hxx>
+#include <mutex>
 
 namespace toolkit
 {
@@ -46,61 +47,48 @@ namespace toolkit
     namespace
     {
 
-        ::osl::Mutex& getDefaultFormatsMutex()
+        std::mutex& getDefaultFormatsMutex()
         {
-            static ::osl::Mutex s_aDefaultFormatsMutex;
+            static std::mutex s_aDefaultFormatsMutex;
             return s_aDefaultFormatsMutex;
         }
 
-
-        Reference< XNumberFormatsSupplier >& 
lcl_getDefaultFormatsAccess_nothrow()
-        {
-            static Reference< XNumberFormatsSupplier > s_xDefaultFormats;
-            return s_xDefaultFormats;
-        }
-
-
+        Reference< XNumberFormatsSupplier > s_xDefaultFormats;
         bool s_bTriedCreation = false;
+        oslInterlockedCount  s_refCount(0);
 
         const Reference< XNumberFormatsSupplier >& 
lcl_getDefaultFormats_throw()
         {
-            ::osl::MutexGuard aGuard( getDefaultFormatsMutex() );
+            std::scoped_lock aGuard( getDefaultFormatsMutex() );
 
-            Reference< XNumberFormatsSupplier >& rDefaultFormats( 
lcl_getDefaultFormatsAccess_nothrow() );
-            if ( !rDefaultFormats.is() && !s_bTriedCreation )
+            if ( !s_xDefaultFormats.is() && !s_bTriedCreation )
             {
                 s_bTriedCreation = true;
-                rDefaultFormats = 
NumberFormatsSupplier::createWithDefaultLocale( 
::comphelper::getProcessComponentContext() );
+                s_xDefaultFormats = 
NumberFormatsSupplier::createWithDefaultLocale( 
::comphelper::getProcessComponentContext() );
             }
-            if ( !rDefaultFormats.is() )
+            if ( !s_xDefaultFormats.is() )
                 throw RuntimeException();
 
-            return rDefaultFormats;
+            return s_xDefaultFormats;
         }
 
-
-        oslInterlockedCount  s_refCount(0);
-
-
         void    lcl_registerDefaultFormatsClient()
         {
             osl_atomic_increment( &s_refCount );
         }
 
-
         void    lcl_revokeDefaultFormatsClient()
         {
-            ::osl::ClearableMutexGuard aGuard( getDefaultFormatsMutex() );
-            if ( 0 == osl_atomic_decrement( &s_refCount ) )
+            Reference< XNumberFormatsSupplier > xReleasePotentialLastReference;
             {
-                Reference< XNumberFormatsSupplier >& rDefaultFormats( 
lcl_getDefaultFormatsAccess_nothrow() );
-                Reference< XNumberFormatsSupplier > 
xReleasePotentialLastReference( rDefaultFormats );
-                rDefaultFormats.clear();
-                s_bTriedCreation = false;
+                std::scoped_lock aGuard( getDefaultFormatsMutex() );
+                if ( 0 != osl_atomic_decrement( &s_refCount ) )
+                    return;
 
-                aGuard.clear();
-                xReleasePotentialLastReference.clear();
+                xReleasePotentialLastReference = std::move(s_xDefaultFormats);
+                s_bTriedCreation = false;
             }
+            xReleasePotentialLastReference.clear();
         }
     }
 

Reply via email to