Kaydet (Commit) 4c93de2c authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ec665e3e
......@@ -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() )
{
......
......@@ -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
......
......@@ -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 ==
......
......@@ -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;
......
......@@ -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
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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;
......
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