diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-11-11 20:40:22 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-13 07:34:25 +0100 |
commit | f4a2c9e91e6b12d4d66b35146ec87b15b365f57d (patch) | |
tree | c2a95a06a1528093a68aaf0d1e1d72f8fefc1995 | |
parent | 98a2cef1ee9c76897af64ff0a1e1efd280796f36 (diff) |
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.grandin@collabora.co.uk>
-rw-r--r-- | include/comphelper/IdPropArrayHelper.hxx | 15 |
1 files changed, 8 insertions, 7 deletions
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) |