diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-11 15:04:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-12 06:53:18 +0000 |
commit | a54172be5a8ec756586fbb5c463364e084aac079 (patch) | |
tree | 017d403bc82bba70d68722598bdceb2c774eecdd | |
parent | 91c954f53f223bcdcfb33fc3625082f05234e16d (diff) |
tsan:lock-order-inversion in FrameworkHelper
simplify initialisation using a regular mutex, which avoids the global
mutex and thus a potential lock ordering issue
Change-Id: Ic32afb827aa0b6aae41b8680d7f7329fbe6bc1ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145341
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sd/source/ui/framework/tools/FrameworkHelper.cxx | 33 | ||||
-rw-r--r-- | sd/source/ui/inc/framework/FrameworkHelper.hxx | 1 |
2 files changed, 11 insertions, 23 deletions
diff --git a/sd/source/ui/framework/tools/FrameworkHelper.cxx b/sd/source/ui/framework/tools/FrameworkHelper.cxx index d712445c25b3..2a10ead3f674 100644 --- a/sd/source/ui/framework/tools/FrameworkHelper.cxx +++ b/sd/source/ui/framework/tools/FrameworkHelper.cxx @@ -39,8 +39,6 @@ #include <utility> #include <vcl/svapp.hxx> -#include <osl/doublecheckedlocking.h> -#include <osl/getglobalmutex.hxx> #include <comphelper/diagnose_ex.hxx> #include <memory> #include <unordered_map> @@ -282,32 +280,21 @@ public: FrameworkHelper::ViewURLMap FrameworkHelper::maViewURLMap; FrameworkHelper::InstanceMap FrameworkHelper::maInstanceMap; +osl::Mutex FrameworkHelper::maInstanceMapMutex; ::std::shared_ptr<FrameworkHelper> FrameworkHelper::Instance (ViewShellBase& rBase) { - - ::std::shared_ptr<FrameworkHelper> pHelper; + ::osl::MutexGuard aGuard(maInstanceMapMutex); InstanceMap::const_iterator iHelper (maInstanceMap.find(&rBase)); - if (iHelper == maInstanceMap.end()) - { - ::osl::GetGlobalMutex aMutexFunctor; - ::osl::MutexGuard aGuard (aMutexFunctor()); - if (iHelper == maInstanceMap.end()) - { - pHelper = ::std::shared_ptr<FrameworkHelper>( - new FrameworkHelper(rBase), - FrameworkHelper::Deleter()); - pHelper->Initialize(); - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - maInstanceMap[&rBase] = pHelper; - } - } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - pHelper = iHelper->second; - } + if (iHelper != maInstanceMap.end()) + return iHelper->second; + + ::std::shared_ptr<FrameworkHelper> pHelper( + new FrameworkHelper(rBase), + FrameworkHelper::Deleter()); + pHelper->Initialize(); + maInstanceMap[&rBase] = pHelper; return pHelper; } diff --git a/sd/source/ui/inc/framework/FrameworkHelper.hxx b/sd/source/ui/inc/framework/FrameworkHelper.hxx index c9bf981bb2a6..4d8278d90ed0 100644 --- a/sd/source/ui/inc/framework/FrameworkHelper.hxx +++ b/sd/source/ui/inc/framework/FrameworkHelper.hxx @@ -293,6 +293,7 @@ private: static InstanceMap maInstanceMap; class ViewURLMap; static ViewURLMap maViewURLMap; + static osl::Mutex maInstanceMapMutex; ViewShellBase& mrBase; css::uno::Reference<css::drawing::framework::XConfigurationController> |