Kaydet (Commit) f76b3dd0 authored tarafından Michael Meeks's avatar Michael Meeks

Move SolarMutex down from tools to comphelper/ to make life easier.

Change-Id: I7dd21f30daa27e5de2848eb16aee9a610dd629d5
Reviewed-on: https://gerrit.libreoffice.org/19271Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 3e23ee07
...@@ -18,11 +18,30 @@ ...@@ -18,11 +18,30 @@
*/ */
#include <sal/config.h> #include <sal/config.h>
#include <assert.h>
#include <comphelper/solarmutex.hxx> #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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -26,8 +26,15 @@ ...@@ -26,8 +26,15 @@
namespace comphelper { 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 { class COMPHELPER_DLLPUBLIC SolarMutex {
public: public:
virtual void acquire() = 0; virtual void acquire() = 0;
...@@ -36,6 +43,12 @@ public: ...@@ -36,6 +43,12 @@ public:
virtual bool tryToAcquire() = 0; 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: protected:
SolarMutex(); SolarMutex();
......
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
namespace tools namespace tools
{ {
/// Deprecated in favour of comphelper::SolarMutex
class TOOLS_DLLPUBLIC SolarMutex class TOOLS_DLLPUBLIC SolarMutex
{ {
public: public:
static void SetSolarMutex( comphelper::SolarMutex* pMutex );
static bool Acquire(); static bool Acquire();
static void Release(); static void Release();
}; };
......
...@@ -21,15 +21,9 @@ ...@@ -21,15 +21,9 @@
namespace tools namespace tools
{ {
static comphelper::SolarMutex* pSolarMutex = 0;
void SolarMutex::SetSolarMutex( comphelper::SolarMutex* pMutex )
{
pSolarMutex = pMutex;
}
bool SolarMutex::Acquire() bool SolarMutex::Acquire()
{ {
comphelper::SolarMutex *pSolarMutex = comphelper::SolarMutex::get();
if ( pSolarMutex ) if ( pSolarMutex )
pSolarMutex->acquire(); pSolarMutex->acquire();
else else
...@@ -39,6 +33,7 @@ namespace tools ...@@ -39,6 +33,7 @@ namespace tools
void SolarMutex::Release() void SolarMutex::Release()
{ {
comphelper::SolarMutex *pSolarMutex = comphelper::SolarMutex::get();
if ( pSolarMutex ) if ( pSolarMutex )
pSolarMutex->release(); pSolarMutex->release();
} }
......
...@@ -40,7 +40,8 @@ ...@@ -40,7 +40,8 @@
#include <com/sun/star/util/XStringEscape.hpp> #include <com/sun/star/util/XStringEscape.hpp>
#include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/util/XChangesBatch.hpp>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <tools/solarmutex.hxx> #include <comphelper/solarmutex.hxx>
#include <rtl/ref.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
using namespace utl; using namespace utl;
...@@ -155,11 +156,12 @@ void ConfigChangeListener_Impl::changesOccurred( const ChangesEvent& rEvent ) th ...@@ -155,11 +156,12 @@ void ConfigChangeListener_Impl::changesOccurred( const ChangesEvent& rEvent ) th
} }
if( nNotify ) if( nNotify )
{ {
if ( ::tools::SolarMutex::Acquire() ) ::comphelper::SolarMutex *pMutex = ::comphelper::SolarMutex::get();
if ( pMutex )
{ {
rtl::Reference< comphelper::SolarMutex > aGuard( pMutex );
aChangedNames.realloc(nNotify); aChangedNames.realloc(nNotify);
pParent->CallNotify(aChangedNames); pParent->CallNotify(aChangedNames);
::tools::SolarMutex::Release();
} }
} }
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <osl/module.hxx> #include <osl/module.hxx>
#include <tools/solarmutex.hxx> #include <comphelper/solarmutex.hxx>
#include <vcl/opengl/OpenGLContext.hxx> #include <vcl/opengl/OpenGLContext.hxx>
#include "generic/geninst.h" #include "generic/geninst.h"
...@@ -32,12 +32,12 @@ SalYieldMutex::SalYieldMutex() ...@@ -32,12 +32,12 @@ SalYieldMutex::SalYieldMutex()
{ {
mnCount = 0; mnCount = 0;
mnThreadId = 0; mnThreadId = 0;
::tools::SolarMutex::SetSolarMutex( this ); ::comphelper::SolarMutex::setSolarMutex( this );
} }
SalYieldMutex::~SalYieldMutex() SalYieldMutex::~SalYieldMutex()
{ {
::tools::SolarMutex::SetSolarMutex( NULL ); ::comphelper::SolarMutex::setSolarMutex( NULL );
} }
void SalYieldMutex::acquire() void SalYieldMutex::acquire()
...@@ -125,7 +125,6 @@ bool SalGenericInstance::CheckYieldMutex() ...@@ -125,7 +125,6 @@ bool SalGenericInstance::CheckYieldMutex()
SalGenericInstance::~SalGenericInstance() SalGenericInstance::~SalGenericInstance()
{ {
::tools::SolarMutex::SetSolarMutex( 0 );
delete mpSalYieldMutex; delete mpSalYieldMutex;
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <tools/solarmutex.hxx> #include <comphelper/solarmutex.hxx>
#include "comphelper/lok.hxx" #include "comphelper/lok.hxx"
...@@ -350,7 +350,7 @@ AquaSalInstance::AquaSalInstance() ...@@ -350,7 +350,7 @@ AquaSalInstance::AquaSalInstance()
{ {
mpSalYieldMutex = new SalYieldMutex; mpSalYieldMutex = new SalYieldMutex;
mpSalYieldMutex->acquire(); mpSalYieldMutex->acquire();
::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex ); ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex );
maMainThread = osl::Thread::getCurrentIdentifier(); maMainThread = osl::Thread::getCurrentIdentifier();
mbWaitingYield = false; mbWaitingYield = false;
maUserEventListMutex = osl_createMutex(); maUserEventListMutex = osl_createMutex();
...@@ -360,7 +360,7 @@ AquaSalInstance::AquaSalInstance() ...@@ -360,7 +360,7 @@ AquaSalInstance::AquaSalInstance()
AquaSalInstance::~AquaSalInstance() AquaSalInstance::~AquaSalInstance()
{ {
::tools::SolarMutex::SetSolarMutex( 0 ); ::comphelper::SolarMutex::setSolarMutex( 0 );
mpSalYieldMutex->release(); mpSalYieldMutex->release();
delete mpSalYieldMutex; delete mpSalYieldMutex;
osl_destroyMutex( maUserEventListMutex ); osl_destroyMutex( maUserEventListMutex );
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include <comphelper/solarmutex.hxx> #include <comphelper/solarmutex.hxx>
#include <tools/solarmutex.hxx>
#include <vcl/apptypes.hxx> #include <vcl/apptypes.hxx>
#include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/opengl/OpenGLHelper.hxx>
#include <vcl/opengl/OpenGLContext.hxx> #include <vcl/opengl/OpenGLContext.hxx>
...@@ -580,12 +578,12 @@ WinSalInstance::WinSalInstance() ...@@ -580,12 +578,12 @@ WinSalInstance::WinSalInstance()
mpSalWaitMutex = new osl::Mutex; mpSalWaitMutex = new osl::Mutex;
mnYieldWaitCount = 0; mnYieldWaitCount = 0;
mpSalYieldMutex->acquire(); mpSalYieldMutex->acquire();
::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex ); ::comphelper::SolarMutex::setSolarMutex( mpSalYieldMutex );
} }
WinSalInstance::~WinSalInstance() WinSalInstance::~WinSalInstance()
{ {
::tools::SolarMutex::SetSolarMutex( 0 ); ::comphelper::SolarMutex::setSolarMutex( 0 );
mpSalYieldMutex->release(); mpSalYieldMutex->release();
delete mpSalYieldMutex; delete mpSalYieldMutex;
delete mpSalWaitMutex; delete mpSalWaitMutex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment