[Libreoffice-commits] core.git: comphelper/source include/comphelper include/tools tools/source unotools/source vcl/generic vcl/osx vcl/win

Michael Meeks michael.meeks at collabora.com
Fri Oct 9 07:52:09 PDT 2015


 comphelper/source/misc/solarmutex.cxx |   25 ++++++++++++++++++++++---
 include/comphelper/solarmutex.hxx     |   17 +++++++++++++++--
 include/tools/solarmutex.hxx          |    2 +-
 tools/source/misc/solarmutex.cxx      |    9 ++-------
 unotools/source/config/configitem.cxx |    8 +++++---
 vcl/generic/app/geninst.cxx           |    7 +++----
 vcl/osx/salinst.cxx                   |    6 +++---
 vcl/win/source/app/salinst.cxx        |    6 ++----
 8 files changed, 53 insertions(+), 27 deletions(-)

New commits:
commit f76b3dd039818cc2b297fa2a11b60d9e055e6d8c
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Oct 9 11:27:26 2015 +0100

    Move SolarMutex down from tools to comphelper/ to make life easier.
    
    Change-Id: I7dd21f30daa27e5de2848eb16aee9a610dd629d5
    Reviewed-on: https://gerrit.libreoffice.org/19271
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/comphelper/source/misc/solarmutex.cxx b/comphelper/source/misc/solarmutex.cxx
index 0eecac8..1d23754 100644
--- a/comphelper/source/misc/solarmutex.cxx
+++ b/comphelper/source/misc/solarmutex.cxx
@@ -18,11 +18,30 @@
  */
 
 #include <sal/config.h>
-
+#include <assert.h>
 #include <comphelper/solarmutex.hxx>
 
-comphelper::SolarMutex::SolarMutex() {}
+namespace comphelper {
+
+SolarMutex::SolarMutex() {}
+
+SolarMutex::~SolarMutex() {}
+
+namespace {
+    static SolarMutex* pSolarMutex = 0;
+}
+
+void SolarMutex::setSolarMutex( SolarMutex *pMutex )
+{
+    assert((pMutex && !pSolarMutex) || !pMutex);
+    pSolarMutex = pMutex;
+}
+
+SolarMutex *SolarMutex::get()
+{
+    return pSolarMutex;
+}
 
-comphelper::SolarMutex::~SolarMutex() {}
+} // namespace comphelper
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/solarmutex.hxx b/include/comphelper/solarmutex.hxx
index 3b66a00..c50eba2 100644
--- a/include/comphelper/solarmutex.hxx
+++ b/include/comphelper/solarmutex.hxx
@@ -26,8 +26,15 @@
 
 namespace comphelper {
 
-/** SolarMutex interface, needed for Application::GetSolarMutex().
-*/
+/**
+ * Abstract SolarMutex interface, needed for VCL's
+ * Application::GetSolarMutex().
+ *
+ * The SolarMutex is the one big recursive code lock used
+ * to protect the vast majority of the LibreOffice code-base,
+ * in particular anything that is graphical and the cores of
+ * the applications.
+ */
 class COMPHELPER_DLLPUBLIC SolarMutex {
 public:
     virtual void acquire() = 0;
@@ -36,6 +43,12 @@ public:
 
     virtual bool tryToAcquire() = 0;
 
+    /// Help components to get the SolarMutex easily.
+    static SolarMutex *get();
+
+    /// semi-private: allow VCL to push its one-big-lock down here.
+    static void setSolarMutex( SolarMutex *pMutex );
+
 protected:
     SolarMutex();
 
diff --git a/include/tools/solarmutex.hxx b/include/tools/solarmutex.hxx
index 85e465d..60af81c 100644
--- a/include/tools/solarmutex.hxx
+++ b/include/tools/solarmutex.hxx
@@ -24,10 +24,10 @@
 
 namespace tools
 {
+    /// Deprecated in favour of comphelper::SolarMutex
     class TOOLS_DLLPUBLIC SolarMutex
     {
     public:
-        static void SetSolarMutex( comphelper::SolarMutex* pMutex );
         static bool Acquire();
         static void Release();
     };
diff --git a/tools/source/misc/solarmutex.cxx b/tools/source/misc/solarmutex.cxx
index f718999..6602939 100644
--- a/tools/source/misc/solarmutex.cxx
+++ b/tools/source/misc/solarmutex.cxx
@@ -21,15 +21,9 @@
 
 namespace tools
 {
-    static comphelper::SolarMutex* pSolarMutex = 0;
-
-    void SolarMutex::SetSolarMutex( comphelper::SolarMutex* pMutex )
-    {
-        pSolarMutex = pMutex;
-    }
-
     bool SolarMutex::Acquire()
     {
+        comphelper::SolarMutex *pSolarMutex = comphelper::SolarMutex::get();
         if ( pSolarMutex )
             pSolarMutex->acquire();
         else
@@ -39,6 +33,7 @@ namespace tools
 
     void SolarMutex::Release()
     {
+        comphelper::SolarMutex *pSolarMutex = comphelper::SolarMutex::get();
         if ( pSolarMutex )
             pSolarMutex->release();
     }
diff --git a/unotools/source/config/configitem.cxx b/unotools/source/config/configitem.cxx
index fd1c423..7d03ab8 100644
--- a/unotools/source/config/configitem.cxx
+++ b/unotools/source/config/configitem.cxx
@@ -40,7 +40,8 @@
 #include <com/sun/star/util/XStringEscape.hpp>
 #include <com/sun/star/util/XChangesBatch.hpp>
 #include <osl/diagnose.h>
-#include <tools/solarmutex.hxx>
+#include <comphelper/solarmutex.hxx>
+#include <rtl/ref.hxx>
 #include <rtl/ustrbuf.hxx>
 
 using namespace utl;
@@ -155,11 +156,12 @@ void ConfigChangeListener_Impl::changesOccurred( const ChangesEvent& rEvent ) th
     }
     if( nNotify )
     {
-        if ( ::tools::SolarMutex::Acquire() )
+        ::comphelper::SolarMutex *pMutex = ::comphelper::SolarMutex::get();
+        if ( pMutex )
         {
+            rtl::Reference< comphelper::SolarMutex > aGuard( pMutex );
             aChangedNames.realloc(nNotify);
             pParent->CallNotify(aChangedNames);
-            ::tools::SolarMutex::Release();
         }
     }
 }
diff --git a/vcl/generic/app/geninst.cxx b/vcl/generic/app/geninst.cxx
index ef7bec0..d53ed30 100644
--- a/vcl/generic/app/geninst.cxx
+++ b/vcl/generic/app/geninst.cxx
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 
 #include <osl/module.hxx>
-#include <tools/solarmutex.hxx>
+#include <comphelper/solarmutex.hxx>
 #include <vcl/opengl/OpenGLContext.hxx>
 
 #include "generic/geninst.h"
@@ -32,12 +32,12 @@ SalYieldMutex::SalYieldMutex()
 {
     mnCount     = 0;
     mnThreadId  = 0;
-    ::tools::SolarMutex::SetSolarMutex( this );
+    ::comphelper::SolarMutex::setSolarMutex( this );
 }
 
 SalYieldMutex::~SalYieldMutex()
 {
-    ::tools::SolarMutex::SetSolarMutex( NULL );
+    ::comphelper::SolarMutex::setSolarMutex( NULL );
 }
 
 void SalYieldMutex::acquire()
@@ -125,7 +125,6 @@ bool SalGenericInstance::CheckYieldMutex()
 
 SalGenericInstance::~SalGenericInstance()
 {
-    ::tools::SolarMutex::SetSolarMutex( 0 );
     delete mpSalYieldMutex;
 }
 
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index bc9b205..137c72f 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -21,7 +21,7 @@
 
 #include <stdio.h>
 
-#include <tools/solarmutex.hxx>
+#include <comphelper/solarmutex.hxx>
 
 #include "comphelper/lok.hxx"
 
@@ -350,7 +350,7 @@ AquaSalInstance::AquaSalInstance()
 {
     mpSalYieldMutex = new SalYieldMutex;
     mpSalYieldMutex->acquire();
-    ::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex );
+    ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex );
     maMainThread = osl::Thread::getCurrentIdentifier();
     mbWaitingYield = false;
     maUserEventListMutex = osl_createMutex();
@@ -360,7 +360,7 @@ AquaSalInstance::AquaSalInstance()
 
 AquaSalInstance::~AquaSalInstance()
 {
-    ::tools::SolarMutex::SetSolarMutex( 0 );
+    ::comphelper::SolarMutex::setSolarMutex( 0 );
     mpSalYieldMutex->release();
     delete mpSalYieldMutex;
     osl_destroyMutex( maUserEventListMutex );
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx
index 27af73f..4f3a289 100644
--- a/vcl/win/source/app/salinst.cxx
+++ b/vcl/win/source/app/salinst.cxx
@@ -24,8 +24,6 @@
 #include <osl/file.hxx>
 #include <comphelper/solarmutex.hxx>
 
-#include <tools/solarmutex.hxx>
-
 #include <vcl/apptypes.hxx>
 #include <vcl/opengl/OpenGLHelper.hxx>
 #include <vcl/opengl/OpenGLContext.hxx>
@@ -580,12 +578,12 @@ WinSalInstance::WinSalInstance()
     mpSalWaitMutex           = new osl::Mutex;
     mnYieldWaitCount         = 0;
     mpSalYieldMutex->acquire();
-    ::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex );
+    ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex );
 }
 
 WinSalInstance::~WinSalInstance()
 {
-    ::tools::SolarMutex::SetSolarMutex( 0 );
+    ::comphelper::SolarMutex::setSolarMutex( 0 );
     mpSalYieldMutex->release();
     delete mpSalYieldMutex;
     delete mpSalWaitMutex;


More information about the Libreoffice-commits mailing list