From f76b3dd039818cc2b297fa2a11b60d9e055e6d8c Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 9 Oct 2015 11:27:26 +0100 Subject: [PATCH] Move SolarMutex down from tools to comphelper/ to make life easier. Change-Id: I7dd21f30daa27e5de2848eb16aee9a610dd629d5 Reviewed-on: https://gerrit.libreoffice.org/19271 Tested-by: Jenkins Reviewed-by: Michael Meeks --- 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(-) 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 - +#include #include -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 #include #include -#include +#include +#include #include 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 #include -#include +#include #include #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 -#include +#include #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 #include -#include - #include #include #include @@ -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; -- 2.9.3