[Libreoffice-commits] core.git: comphelper/source include/comphelper vcl/headless vcl/inc vcl/osx vcl/README.scheduler vcl/win
Noel Grandin
noel.grandin at collabora.co.uk
Thu Jun 21 06:20:19 UTC 2018
comphelper/source/misc/solarmutex.cxx | 31 +++++-----------
include/comphelper/solarmutex.hxx | 63 +++++++++-------------------------
vcl/README.scheduler | 2 -
vcl/headless/svpinst.cxx | 2 -
vcl/inc/osx/salinst.h | 2 -
vcl/inc/unx/geninst.h | 2 -
vcl/osx/salinst.cxx | 6 +--
vcl/win/app/salinst.cxx | 8 ++--
8 files changed, 40 insertions(+), 76 deletions(-)
New commits:
commit 4c93de2c921b43193985c057b03e329d6dddc5d4
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Wed Jun 20 11:13:44 2018 +0200
merge GenericSolarMutex and SolarMutex
Since nothing else is implementing the SolarMutex abstract class.
Change-Id: I2a41254af3e9c7534033cdd0bece9dd8e0258b9d
Reviewed-on: https://gerrit.libreoffice.org/56153
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/comphelper/source/misc/solarmutex.cxx b/comphelper/source/misc/solarmutex.cxx
index 1501228b1bc6..3af24dadb4c7 100644
--- a/comphelper/source/misc/solarmutex.cxx
+++ b/comphelper/source/misc/solarmutex.cxx
@@ -26,39 +26,30 @@
namespace comphelper {
-SolarMutex::SolarMutex() {}
-
-SolarMutex::~SolarMutex() {}
-
namespace {
- static SolarMutex* pSolarMutex = nullptr;
-}
-
-void SolarMutex::setSolarMutex( SolarMutex *pMutex )
-{
- assert((pMutex && !pSolarMutex) || !pMutex);
- pSolarMutex = pMutex;
+ static SolarMutex* g_pSolarMutex = nullptr;
}
SolarMutex *SolarMutex::get()
{
- return pSolarMutex;
+ return g_pSolarMutex;
}
-GenericSolarMutex::GenericSolarMutex()
+SolarMutex::SolarMutex()
: m_nCount( 0 )
, m_nThreadId( 0 )
, m_aBeforeReleaseHandler( nullptr )
{
- setSolarMutex( this );
+ assert(!g_pSolarMutex);
+ g_pSolarMutex = this;
}
-GenericSolarMutex::~GenericSolarMutex()
+SolarMutex::~SolarMutex()
{
- setSolarMutex( nullptr );
+ g_pSolarMutex = nullptr;
}
-void GenericSolarMutex::doAcquire( const sal_uInt32 nLockCount )
+void SolarMutex::doAcquire( const sal_uInt32 nLockCount )
{
for ( sal_uInt32 n = nLockCount; n ; --n )
m_aMutex.acquire();
@@ -66,7 +57,7 @@ void GenericSolarMutex::doAcquire( const sal_uInt32 nLockCount )
m_nCount += nLockCount;
}
-sal_uInt32 GenericSolarMutex::doRelease( bool bUnlockAll )
+sal_uInt32 SolarMutex::doRelease( bool bUnlockAll )
{
if ( m_nCount == 0 )
std::abort();
@@ -89,12 +80,12 @@ sal_uInt32 GenericSolarMutex::doRelease( bool bUnlockAll )
return nCount;
}
-bool GenericSolarMutex::IsCurrentThread() const
+bool SolarMutex::IsCurrentThread() const
{
return m_nThreadId == osl::Thread::getCurrentIdentifier();
}
-bool GenericSolarMutex::tryToAcquire()
+bool SolarMutex::tryToAcquire()
{
if ( m_aMutex.tryToAcquire() )
{
diff --git a/include/comphelper/solarmutex.hxx b/include/comphelper/solarmutex.hxx
index e00f51dd728a..890b3e3762dd 100644
--- a/include/comphelper/solarmutex.hxx
+++ b/include/comphelper/solarmutex.hxx
@@ -30,23 +30,30 @@ namespace comphelper {
/**
- * Abstract SolarMutex interface, needed for VCL's
- * Application::GetSolarMutex().
+ * SolarMutex, 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.
+ *
+ * Treat this as a singleton, as its constructor sets a global
+ * pointing at itself.
*/
class COMPHELPER_DLLPUBLIC SolarMutex {
public:
+ typedef void (*BeforeReleaseHandler) ();
+
+ void SetBeforeReleaseHandler( const BeforeReleaseHandler& rLink )
+ { m_aBeforeReleaseHandler = rLink; }
+
void acquire( sal_uInt32 nLockCount = 1 );
sal_uInt32 release( bool bUnlockAll = false );
- virtual bool tryToAcquire() = 0;
+ virtual bool tryToAcquire();
// returns true, if the mutex is owned by the current thread
- virtual bool IsCurrentThread() const = 0;
+ virtual bool IsCurrentThread() const;
/// Help components to get the SolarMutex easily.
static SolarMutex *get();
@@ -55,15 +62,18 @@ protected:
SolarMutex();
virtual ~SolarMutex();
- /// allow VCL to push its one-big-lock down here.
- static void setSolarMutex( SolarMutex *pMutex );
+ virtual sal_uInt32 doRelease( bool bUnlockAll );
+ virtual void doAcquire( sal_uInt32 nLockCount );
- virtual sal_uInt32 doRelease( bool bUnlockAll ) = 0;
- virtual void doAcquire( sal_uInt32 nLockCount ) = 0;
+ osl::Mutex m_aMutex;
+ sal_uInt32 m_nCount;
+ oslThreadIdentifier m_nThreadId;
private:
SolarMutex(const SolarMutex&) = delete;
SolarMutex& operator=(const SolarMutex&) = delete;
+
+ BeforeReleaseHandler m_aBeforeReleaseHandler;
};
inline void SolarMutex::acquire( sal_uInt32 nLockCount )
@@ -77,43 +87,6 @@ inline sal_uInt32 SolarMutex::release( bool bUnlockAll )
return doRelease( bUnlockAll );
}
-
-/**
- * Generic implementation of the abstract SolarMutex interface.
- *
- * Treat this as a singleton, as its constructor calls
- * setSolarMutex( this )!
- *
- * Kept separated from SolarMutex, so others can implement facades.
- */
-class COMPHELPER_DLLPUBLIC GenericSolarMutex
- : public SolarMutex
-{
-public:
- typedef void (*BeforeReleaseHandler) ();
-
- void SetBeforeReleaseHandler( const BeforeReleaseHandler& rLink )
- { m_aBeforeReleaseHandler = rLink; }
-
- virtual bool tryToAcquire() override;
- virtual bool IsCurrentThread() const override;
-
-protected:
- osl::Mutex m_aMutex;
- sal_uInt32 m_nCount;
- oslThreadIdentifier m_nThreadId;
-
- virtual void doAcquire( sal_uInt32 nLockCount ) override;
- virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
-
-protected:
- GenericSolarMutex();
- virtual ~GenericSolarMutex() override;
-
-private:
- BeforeReleaseHandler m_aBeforeReleaseHandler;
-};
-
}
#endif // INCLUDED_COMPHELPER_SOLARMUTEX_HXX
diff --git a/vcl/README.scheduler b/vcl/README.scheduler
index 80c14b032c54..47edd9283c42 100644
--- a/vcl/README.scheduler
+++ b/vcl/README.scheduler
@@ -130,7 +130,7 @@ Since we just disable the locks when we start running the deferred code in the
main thread, we won't let the main thread run into stuff, where it would
normally wait for the SolarMutex.
-Eventually this will move into the GenericSolarMutex. KDE / Qt also does main
+Eventually this will move into the SolarMutex. KDE / Qt also does main
thread redirects using Qt::BlockingQueuedConnection.
== General: processing all current events for DoYield ==
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 3b43c46aae36..22146014dbfc 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -360,7 +360,7 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll)
{
// read m_nCount before doRelease
bool const isReleased(bUnlockAll || m_nCount == 1);
- nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll );
+ nCount = comphelper::SolarMutex::doRelease( bUnlockAll );
if (isReleased) {
std::unique_lock<std::mutex> g(m_WakeUpMainMutex);
m_wakeUpMain = true;
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index 13261df0d25a..8e15730a3843 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -49,7 +49,7 @@ enum class SalEvent;
typedef void(^RuninmainBlock)(void);
-class SalYieldMutex : public comphelper::GenericSolarMutex
+class SalYieldMutex : public comphelper::SolarMutex
{
public:
OSX_RUNINMAIN_MEMBERS
diff --git a/vcl/inc/unx/geninst.h b/vcl/inc/unx/geninst.h
index 3b9b7b79ca82..a1c5959f3b69 100644
--- a/vcl/inc/unx/geninst.h
+++ b/vcl/inc/unx/geninst.h
@@ -28,7 +28,7 @@
#include <saldatabasic.hxx>
#include <unx/genprn.h>
-class VCL_DLLPUBLIC SalYieldMutex : public comphelper::GenericSolarMutex
+class VCL_DLLPUBLIC SalYieldMutex : public comphelper::SolarMutex
{
public:
SalYieldMutex();
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 972a7fafcd76..b046fda9f4e2 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -318,7 +318,7 @@ void SalYieldMutex::doAcquire( sal_uInt32 nLockCount )
++m_nCount;
--nLockCount;
- comphelper::GenericSolarMutex::doAcquire( nLockCount );
+ comphelper::SolarMutex::doAcquire( nLockCount );
}
sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll )
@@ -331,7 +331,7 @@ sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll )
std::unique_lock<std::mutex> g(m_runInMainMutex);
// read m_nCount before doRelease
bool const isReleased(bUnlockAll || m_nCount == 1);
- nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll );
+ nCount = comphelper::SolarMutex::doRelease( bUnlockAll );
if (isReleased && !pInst->IsMainThread()) {
m_wakeUpMain = true;
m_aInMainCondition.notify_all();
@@ -343,7 +343,7 @@ sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll )
bool SalYieldMutex::IsCurrentThread() const
{
if ( !GetSalData()->mpInstance->mbNoYieldLock )
- return comphelper::GenericSolarMutex::IsCurrentThread();
+ return comphelper::SolarMutex::IsCurrentThread();
else
return GetSalData()->mpInstance->IsMainThread();
}
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index cfdc68b4ac43..468cff39f485 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -86,7 +86,7 @@ void SalAbort( const OUString& rErrorText, bool )
LRESULT CALLBACK SalComWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
-class SalYieldMutex : public comphelper::GenericSolarMutex
+class SalYieldMutex : public comphelper::SolarMutex
{
public: // for ImplSalYield() and ImplSalYieldMutexAcquireWithWait()
osl::Condition m_condition; /// for MsgWaitForMultipleObjects()
@@ -154,7 +154,7 @@ void SalYieldMutex::doAcquire( sal_uInt32 nLockCount )
++m_nCount;
--nLockCount;
- comphelper::GenericSolarMutex::doAcquire( nLockCount );
+ comphelper::SolarMutex::doAcquire( nLockCount );
}
sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll )
@@ -163,7 +163,7 @@ sal_uInt32 SalYieldMutex::doRelease( const bool bUnlockAll )
if ( pInst && pInst->mbNoYieldLock && pInst->IsMainThread() )
return 1;
- sal_uInt32 nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll );
+ sal_uInt32 nCount = comphelper::SolarMutex::doRelease( bUnlockAll );
// wake up ImplSalYieldMutexAcquireWithWait() after release
if ( 0 == m_nCount )
m_condition.set();
@@ -178,7 +178,7 @@ bool SalYieldMutex::tryToAcquire()
if ( pInst->mbNoYieldLock && pInst->IsMainThread() )
return true;
else
- return comphelper::GenericSolarMutex::tryToAcquire();
+ return comphelper::SolarMutex::tryToAcquire();
}
else
return false;
More information about the Libreoffice-commits
mailing list