sd/source/ui/sidebar/MasterPageObserver.cxx |   34 +++++-----------------------
 1 file changed, 7 insertions(+), 27 deletions(-)

New commits:
commit 244803ee2bcdfd4c4244f0c8a0654dab25fbc34d
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 11 15:02:59 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jan 12 06:53:29 2023 +0000

    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.gran...@collabora.co.uk>

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)

Reply via email to