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

generic: share sal yield mutex properly

üst ef93683d
......@@ -31,7 +31,6 @@ $(eval $(call gb_Module_Module,vcl))
$(eval $(call gb_Module_add_targets,vcl,\
Library_vcl \
Library_vclplug_svp \
StaticLibrary_vclmain \
Package_inc \
Package_afmhash \
......@@ -40,6 +39,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
ifeq ($(GUIBASE),unx)
$(eval $(call gb_Module_add_targets,vcl,\
Library_vclplug_svp \
Library_vclplug_gen \
Library_desktop_detector \
))
......
......@@ -53,7 +53,7 @@ extern "C"
{
SAL_DLLPUBLIC_EXPORT SalInstance* create_SalInstance()
{
SvpSalInstance* pInstance = new SvpSalInstance();
SvpSalInstance* pInstance = new SvpSalInstance( new SalYieldMutex() );
SalData* pSalData = new SalData();
pSalData->m_pInstance = pInstance;
SetSalData( pSalData );
......@@ -77,8 +77,8 @@ bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const
SvpSalInstance* SvpSalInstance::s_pDefaultInstance = NULL;
SvpSalInstance::SvpSalInstance() :
SalGenericInstance( new SalYieldMutex() )
SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
SalGenericInstance( pMutex )
{
m_aTimeout.tv_sec = 0;
m_aTimeout.tv_usec = 0;
......@@ -304,51 +304,6 @@ SalBitmap* SvpSalInstance::CreateSalBitmap()
return new SvpSalBitmap();
}
osl::SolarMutex* SvpSalInstance::GetYieldMutex()
{
return &m_aYieldMutex;
}
sal_uLong SvpSalInstance::ReleaseYieldMutex()
{
if ( m_aYieldMutex.GetThreadId() ==
osl::Thread::getCurrentIdentifier() )
{
sal_uLong nCount = m_aYieldMutex.GetAcquireCount();
sal_uLong n = nCount;
while ( n )
{
m_aYieldMutex.release();
n--;
}
return nCount;
}
else
return 0;
}
void SvpSalInstance::AcquireYieldMutex( sal_uLong nCount )
{
while ( nCount )
{
m_aYieldMutex.acquire();
nCount--;
}
}
bool SvpSalInstance::CheckYieldMutex()
{
bool bRet = true;
if ( m_aYieldMutex.GetThreadId() != ::osl::Thread::getCurrentIdentifier() )
{
bRet = false;
}
return bRet;
}
void SvpSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
{
// first, check for already queued events.
......@@ -453,48 +408,6 @@ void* SvpSalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturn
return const_cast<char*>("");
}
// -------------------------------------------------------------------------
//
// SalYieldMutex
//
// -------------------------------------------------------------------------
SvpSalYieldMutex::SvpSalYieldMutex()
{
mnCount = 0;
mnThreadId = 0;
}
void SvpSalYieldMutex::acquire()
{
SolarMutexObject::acquire();
mnThreadId = osl::Thread::getCurrentIdentifier();
mnCount++;
}
void SvpSalYieldMutex::release()
{
if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
{
if ( mnCount == 1 )
mnThreadId = 0;
mnCount--;
}
SolarMutexObject::release();
}
sal_Bool SvpSalYieldMutex::tryToAcquire()
{
if ( SolarMutexObject::tryToAcquire() )
{
mnThreadId = osl::Thread::getCurrentIdentifier();
mnCount++;
return sal_True;
}
else
return sal_False;
}
// ---------------
// - SalTimer -
// ---------------
......
......@@ -46,27 +46,6 @@
#define VIRTUAL_DESKTOP_HEIGHT 768
#define VIRTUAL_DESKTOP_DEPTH 24
// -------------------------------------------------------------------------
// SalYieldMutex
// -------------------------------------------------------------------------
class SvpSalYieldMutex : public ::vcl::SolarMutexObject
{
protected:
sal_uLong mnCount;
oslThreadIdentifier mnThreadId;
public:
SvpSalYieldMutex();
virtual void acquire();
virtual void release();
virtual sal_Bool tryToAcquire();
sal_uLong GetAcquireCount() const { return mnCount; }
oslThreadIdentifier GetThreadId() const { return mnThreadId; }
};
// ---------------
// - SalTimer -
// ---------------
......@@ -92,7 +71,6 @@ class SvpSalInstance : public SalGenericInstance
timeval m_aTimeout;
sal_uLong m_nTimeoutMS;
int m_pTimeoutFDS[2];
SvpSalYieldMutex m_aYieldMutex;
// internal event queue
struct SalUserEvent
......@@ -118,7 +96,7 @@ class SvpSalInstance : public SalGenericInstance
public:
static SvpSalInstance* s_pDefaultInstance;
SvpSalInstance();
SvpSalInstance( SalYieldMutex *pMutex );
virtual ~SvpSalInstance();
void PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
......@@ -177,12 +155,6 @@ public:
// SalBitmap
virtual SalBitmap* CreateSalBitmap();
// YieldMutex
virtual osl::SolarMutex* GetYieldMutex();
virtual sal_uLong ReleaseYieldMutex();
virtual void AcquireYieldMutex( sal_uLong nCount );
virtual bool CheckYieldMutex();
// wait next event and dispatch
// must returned by UserEvent (SalFrame::PostEvent)
// and timer
......
......@@ -82,10 +82,9 @@ public:
#if GTK_CHECK_VERSION(3,0,0)
class GtkInstance : public SvpSalInstance
{
SalYieldMutex *mpSalYieldMutex;
public:
GtkInstance( SalYieldMutex* pMutex )
: SvpSalInstance(), mpSalYieldMutex( pMutex )
: SvpSalInstance( pMutex )
#else
class GtkInstance : public X11SalInstance
{
......@@ -108,10 +107,6 @@ public:
const SystemGraphicsData* );
virtual SalBitmap* CreateSalBitmap();
virtual osl::SolarMutex* GetYieldMutex();
virtual sal_uIntPtr ReleaseYieldMutex();
virtual void AcquireYieldMutex( sal_uIntPtr nCount );
virtual bool CheckYieldMutex();
virtual void Yield( bool bWait, bool bHandleAllCurrentEvents );
virtual bool AnyInput( sal_uInt16 nType );
};
......
......@@ -443,59 +443,7 @@ SalBitmap* GtkInstance::CreateSalBitmap()
SalTimer* GtkInstance::CreateSalTimer()
{
#if GTK_CHECK_VERSION(3,0,0)
return new GtkSalTimer();
#else
return X11SalInstance::CreateSalTimer();
#endif
}
// FIXME: these should all be in a more generic, shared base of unix's salinst.cxx
osl::SolarMutex* GtkInstance::GetYieldMutex()
{
return mpSalYieldMutex;
}
sal_uIntPtr GtkInstance::ReleaseYieldMutex()
{
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
if ( pYieldMutex->GetThreadId() ==
osl::Thread::getCurrentIdentifier() )
{
sal_uLong nCount = pYieldMutex->GetAcquireCount();
sal_uLong n = nCount;
while ( n )
{
pYieldMutex->release();
n--;
}
return nCount;
}
else
return 0;
}
void GtkInstance::AcquireYieldMutex( sal_uIntPtr nCount )
{
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
while ( nCount )
{
pYieldMutex->acquire();
nCount--;
}
}
bool GtkInstance::CheckYieldMutex()
{
bool bRet = true;
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
bRet = false;
return bRet;
}
void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
......
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