include/comphelper/IdPropArrayHelper.hxx |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

New commits:
commit f4a2c9e91e6b12d4d66b35146ec87b15b365f57d
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu Nov 11 20:40:22 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Nov 13 07:34:25 2021 +0100

    rtl::Static->thread-safe static in OIdPropertyArrayUsageHelper
    
    Change-Id: I21ef0fdc1bf83e313d5dd1079167df0ba59aeed3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125116
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/comphelper/IdPropArrayHelper.hxx 
b/include/comphelper/IdPropArrayHelper.hxx
index c702acb98065..705de3db8925 100644
--- a/include/comphelper/IdPropArrayHelper.hxx
+++ b/include/comphelper/IdPropArrayHelper.hxx
@@ -21,7 +21,6 @@
 #include <sal/config.h>
 
 #include <osl/mutex.hxx>
-#include <rtl/instance.hxx>
 #include <cppuhelper/propshlp.hxx>
 #include <cassert>
 #include <unordered_map>
@@ -29,9 +28,6 @@
 namespace comphelper
 {
 
-    template <typename TYPE> struct OIdPropertyArrayUsageHelperMutex
-            : public rtl::Static< ::osl::Mutex, 
OIdPropertyArrayUsageHelperMutex<TYPE> > {};
-
     typedef std::unordered_map< sal_Int32, ::cppu::IPropertyArrayHelper* > 
OIdPropertyArrayMap;
     template <class TYPE>
     class OIdPropertyArrayUsageHelper
@@ -40,7 +36,7 @@ namespace comphelper
         OIdPropertyArrayUsageHelper();
         virtual ~OIdPropertyArrayUsageHelper()
         {
-            ::osl::MutexGuard 
aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
+            ::osl::MutexGuard aGuard(theMutex());
             assert(s_nRefCount > 0 && 
"OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : 
have a refcount of 0 !");
             if (!--s_nRefCount)
             {
@@ -68,6 +64,11 @@ namespace comphelper
     private:
         static sal_Int32                        s_nRefCount;
         static OIdPropertyArrayMap*             s_pMap;
+        static osl::Mutex& theMutex()
+        {
+            static osl::Mutex SINGLETON;
+            return SINGLETON;
+        }
     };
 
     template<class TYPE>
@@ -79,7 +80,7 @@ namespace comphelper
     template <class TYPE>
     OIdPropertyArrayUsageHelper<TYPE>::OIdPropertyArrayUsageHelper()
     {
-        ::osl::MutexGuard 
aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
+        ::osl::MutexGuard aGuard(theMutex());
         // create the map if necessary
         if (!s_pMap)
             s_pMap = new OIdPropertyArrayMap;
@@ -90,7 +91,7 @@ namespace comphelper
     ::cppu::IPropertyArrayHelper* 
OIdPropertyArrayUsageHelper<TYPE>::getArrayHelper(sal_Int32 nId)
     {
         assert(s_nRefCount && "OIdPropertyArrayUsageHelper::getArrayHelper : 
suspicious call : have a refcount of 0 !");
-        ::osl::MutexGuard 
aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
+        ::osl::MutexGuard aGuard(theMutex());
         // do we have the array already?
         auto& rEntry = (*s_pMap)[nId];
         if (!rEntry)

Reply via email to