diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-11 15:02:59 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-12 06:53:29 +0000 |
commit | 244803ee2bcdfd4c4244f0c8a0654dab25fbc34d (patch) | |
tree | bf21839bdfa71eea3d34019408570f19633c032d /sd/source/ui/sidebar | |
parent | a54172be5a8ec756586fbb5c463364e084aac079 (diff) |
tsan:lock-order-inversion in MasterPageObserver
simply the initialisation using a function local static
Change-Id: Ib5b42dccd69e79822b10ab357c357003b35f9d0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145340
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd/source/ui/sidebar')
-rw-r--r-- | sd/source/ui/sidebar/MasterPageObserver.cxx | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/sd/source/ui/sidebar/MasterPageObserver.cxx b/sd/source/ui/sidebar/MasterPageObserver.cxx index 017a0bcdf991..724b7b5e8f86 100644 --- a/sd/source/ui/sidebar/MasterPageObserver.cxx +++ b/sd/source/ui/sidebar/MasterPageObserver.cxx @@ -38,11 +38,6 @@ class MasterPageObserver::Implementation : public SfxListener { public: - /** The single instance of this class. It is created on demand when - Instance() is called for the first time. - */ - static MasterPageObserver* mpInstance; - /** The master page observer will listen to events of this document and detect changes of the use of master pages. */ @@ -91,33 +86,18 @@ private: void SendEvent (MasterPageObserverEvent& rEvent); }; -MasterPageObserver* MasterPageObserver::Implementation::mpInstance = nullptr; - //===== MasterPageObserver ==================================================== MasterPageObserver& MasterPageObserver::Instance() { - if (Implementation::mpInstance == nullptr) + static MasterPageObserver* gInstance = []() { - ::osl::GetGlobalMutex aMutexFunctor; - ::osl::MutexGuard aGuard (aMutexFunctor()); - if (Implementation::mpInstance == nullptr) - { - MasterPageObserver* pInstance = new MasterPageObserver (); - SdGlobalResourceContainer::Instance().AddResource ( - ::std::unique_ptr<SdGlobalResource>(pInstance)); - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - Implementation::mpInstance = pInstance; - } - } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } - - DBG_ASSERT(Implementation::mpInstance!=nullptr, - "MasterPageObserver::Instance(): instance is NULL"); - return *Implementation::mpInstance; + MasterPageObserver* pInstance = new MasterPageObserver (); + SdGlobalResourceContainer::Instance().AddResource ( + ::std::unique_ptr<SdGlobalResource>(pInstance)); + return pInstance; + }(); + return *gInstance; } void MasterPageObserver::RegisterDocument (SdDrawDocument& rDocument) |