Remove unused LOCKTYPE_FRAMEWORK env var override

...which means that only the E_SOLARMUTEX part of LockHelper is ever used.

Change-Id: Ibff0bda324af67c85cbd2975d308c612c66e5052
This commit is contained in:
Stephan Bergmann
2013-05-14 14:01:01 +02:00
parent 61ac80a6f6
commit 4af8a94a96
2 changed files with 20 additions and 264 deletions

View File

@@ -30,23 +30,6 @@
namespace framework{
/*-************************************************************************************************************//**
@descr If you use a lock or mutex as a member of your class and whish to use it earlier then other ones
you should have a look on this implementation. You must use it as the first base class
of your implementation - because base classes are initialized by his order and before your
member! Thats why ist a good place to declare your thread help member so.
*//*-*************************************************************************************************************/
enum ELockType
{
E_NOTHING = 0 ,
E_OWNMUTEX = 1 ,
E_SOLARMUTEX = 2 ,
E_FAIRRWLOCK = 3
};
#define ENVVAR_LOCKTYPE DECLARE_ASCII("LOCKTYPE_FRAMEWORK")
#define FALLBACK_LOCKTYPE E_SOLARMUTEX
/*-************************************************************************************************************//**
@short helper to set right lock in right situation
@descr This helper support different types of locking:
@@ -109,35 +92,12 @@ class FWI_DLLPUBLIC LockHelper : public IMutex
static LockHelper& getGlobalLock ( comphelper::SolarMutex* pSolarMutex = NULL );
::osl::Mutex& getShareableOslMutex( );
//-------------------------------------------------------------------------------------------------------------
// private methods
//-------------------------------------------------------------------------------------------------------------
private:
static ELockType& implts_getLockType();
//-------------------------------------------------------------------------------------------------------------
// private member
// a) Make some member mutable for using in const functions!
// b) "m_eLockType" define, which of follow members is used!
// You can use "m_pFairRWLock" as a fair rw-lock (multiple reader / one writer / looks for incoming order of threads too) ...
// or you can use a normal osl mutex ("m_pOwnMutex") ...
// ... or the solarmuex as "m_pSolarMutex" (must be set from outside! because some components must be vcl-free!)
// ... but sometimes you need a shareable osl mutex!
// In this case you has some problems: i ) If your lock type is set to E_OWNMUTEX => it's easy; you can use your member "m_pOwnMutex" - it's a osl mutex.
// Creation and using of "m_pShareableOslMutex" isn't necessary!
// ii ) Otherwise you have no osl mutex ... so you must create "m_pShareableOslMutex" and use it twice!
// In this case you must lock two member everytime - "m_pShareableMutex" AND "m_pFairRWLock" or "m_pSolarMutex" or ...
// It isn't realy fine - but the only possible way.
// iii) There exist another special case - E_NOTHING is set! Then we should create this shareable mutex ...
// nad you can use it ... but this implmentation ignore it.
// Make some member mutable for using in const functions!
//-------------------------------------------------------------------------------------------------------------
private:
ELockType m_eLockType ;
mutable FairRWLock* m_pFairRWLock ;
mutable ::osl::Mutex* m_pOwnMutex ;
mutable comphelper::SolarMutex* m_pSolarMutex ;
mutable ::osl::Mutex* m_pShareableOslMutex ;
mutable sal_Bool m_bDummySolarMutex ;

View File

@@ -30,11 +30,7 @@ namespace framework{
/*-************************************************************************************************************//**
@short use ctor to initialize instance
@descr We must initialize our member "m_eLockType". This value specify handling of locking.
User use this helper as parameter for a guard creation.
These guard use "m_eLockType" to set lock in the right way by using right mutex or rw-lock.
@seealso enum ELockType
@seealso class ReadGuard
@seealso class WriteGuard
@@ -45,39 +41,18 @@ namespace framework{
@onerror -
*//*-*************************************************************************************************************/
LockHelper::LockHelper( comphelper::SolarMutex* pSolarMutex )
: m_pFairRWLock ( NULL )
, m_pOwnMutex ( NULL )
, m_pSolarMutex ( NULL )
: m_pSolarMutex ( NULL )
, m_pShareableOslMutex( NULL )
, m_bDummySolarMutex ( sal_False )
{
m_eLockType = implts_getLockType();
switch( m_eLockType )
if( pSolarMutex == NULL )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex = new ::osl::Mutex;
}
break;
case E_SOLARMUTEX : {
if( pSolarMutex == NULL )
{
m_pSolarMutex = new ::vcl::SolarMutexObject;
m_bDummySolarMutex = sal_True;
}
else
{
m_pSolarMutex = pSolarMutex;
}
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock = new FairRWLock;
}
break;
#ifdef ENABLE_ASSERTIONS
default : LOG_ASSERT2( m_eLockType!=E_NOTHING, "LockHelper::ctor()", "Invalid lock type found .. so code will not be threadsafe!" )
#endif
m_pSolarMutex = new ::vcl::SolarMutexObject;
m_bDummySolarMutex = sal_True;
}
else
{
m_pSolarMutex = pSolarMutex;
}
}
@@ -97,20 +72,9 @@ LockHelper::~LockHelper()
{
if( m_pShareableOslMutex != NULL )
{
// Sometimes we hold two pointer to same object!
// (e.g. if m_eLockType==E_OWNMUTEX!)
// So we should forget it ... but don't delete it twice!
if( m_pShareableOslMutex != m_pOwnMutex )
{
delete m_pShareableOslMutex;
}
delete m_pShareableOslMutex;
m_pShareableOslMutex = NULL;
}
if( m_pOwnMutex != NULL )
{
delete m_pOwnMutex;
m_pOwnMutex = NULL;
}
if( m_pSolarMutex != NULL )
{
if (m_bDummySolarMutex)
@@ -120,11 +84,6 @@ LockHelper::~LockHelper()
}
m_pSolarMutex = NULL;
}
if( m_pFairRWLock != NULL )
{
delete m_pFairRWLock;
m_pFairRWLock = NULL;
}
}
/*-************************************************************************************************************//**
@@ -146,22 +105,7 @@ LockHelper::~LockHelper()
*//*-*************************************************************************************************************/
void LockHelper::acquire()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->acquire();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->acquire();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->acquireWriteAccess();
}
break;
}
m_pSolarMutex->acquire();
}
/*-************************************************************************************************************//**
@@ -183,22 +127,7 @@ void LockHelper::acquire()
*//*-*************************************************************************************************************/
void LockHelper::release()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->release();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->release();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->releaseWriteAccess();
}
break;
}
m_pSolarMutex->release();
}
/*-************************************************************************************************************//**
@@ -206,7 +135,6 @@ void LockHelper::release()
@short set lock for reading
@descr A guard should call this method to acquire read access on your member.
Writing isn't allowed then - but nobody could check it for you!
We use m_eLockType to differ between all possible "lock-member"!!!
@attention If a shareable osl mutex exist, he must be used as twice!
It's neccessary for some cppu-helper classes ...
@@ -220,29 +148,13 @@ void LockHelper::release()
*//*-*************************************************************************************************************/
void LockHelper::acquireReadAccess()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->acquire();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->acquire();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->acquireReadAccess();
}
break;
}
m_pSolarMutex->acquire();
}
/*-************************************************************************************************************//**
@interface IRWLock
@short reset lock for reading
@descr A guard should call this method to release read access on your member.
We use m_eLockType to differ between all possible "lock-member"!!!
@attention If a shareable osl mutex exist, he must be used as twice!
It's neccessary for some cppu-helper classes ...
@@ -256,22 +168,7 @@ void LockHelper::acquireReadAccess()
*//*-*************************************************************************************************************/
void LockHelper::releaseReadAccess()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->release();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->release();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->releaseReadAccess();
}
break;
}
m_pSolarMutex->release();
}
/*-************************************************************************************************************//**
@@ -280,7 +177,6 @@ void LockHelper::releaseReadAccess()
@descr A guard should call this method to acquire write access on your member.
Reading is allowed too - of course.
After successfully calling of this method you are the only writer.
We use m_eLockType to differ between all possible "lock-member"!!!
@attention If a shareable osl mutex exist, he must be used as twice!
It's neccessary for some cppu-helper classes ...
@@ -294,29 +190,13 @@ void LockHelper::releaseReadAccess()
*//*-*************************************************************************************************************/
void LockHelper::acquireWriteAccess()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->acquire();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->acquire();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->acquireWriteAccess();
}
break;
}
m_pSolarMutex->acquire();
}
/*-************************************************************************************************************//**
@interface IRWLock
@short reset lock for writing
@descr A guard should call this method to release write access on your member.
We use m_eLockType to differ between all possible "lock-member"!!!
@attention If a shareable osl mutex exist, he must be used as twice!
It's neccessary for some cppu-helper classes ...
@@ -330,22 +210,7 @@ void LockHelper::acquireWriteAccess()
*//*-*************************************************************************************************************/
void LockHelper::releaseWriteAccess()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : {
m_pOwnMutex->release();
}
break;
case E_SOLARMUTEX : {
m_pSolarMutex->release();
}
break;
case E_FAIRRWLOCK : {
m_pFairRWLock->releaseWriteAccess();
}
break;
}
m_pSolarMutex->release();
}
/*-************************************************************************************************************//**
@@ -353,7 +218,6 @@ void LockHelper::releaseWriteAccess()
@short downgrade a write access to a read access
@descr A guard should call this method to change a write to a read access.
New readers can work too - new writer are blocked!
We use m_eLockType to differ between all possible "lock-member"!!!
@attention Ignore shareable mutex(!) - because this call never should release a lock completely!
We change a write access to a read access only.
@@ -362,7 +226,7 @@ void LockHelper::releaseWriteAccess()
Results are not defined then ...
An upgrade can't be implemented realy ... because acquiring new access
will be the same - there no differences!
b) Without function if m_eLockTyp is different from E_FAIRRWLOCK(!) ...
b) Without function ...
because, a mutex don't support it realy.
@seealso -
@@ -374,14 +238,7 @@ void LockHelper::releaseWriteAccess()
*//*-*************************************************************************************************************/
void LockHelper::downgradeWriteAccess()
{
switch( m_eLockType )
{
case E_NOTHING : break; // There is nothing to do ...
case E_OWNMUTEX : break; // Not supported for mutex!
case E_SOLARMUTEX : break; // Not supported for mutex!
case E_FAIRRWLOCK : m_pFairRWLock->downgradeWriteAccess();
break;
}
// Not supported for mutex!
}
/*-************************************************************************************************************//**
@@ -428,8 +285,7 @@ LockHelper& LockHelper::getGlobalLock( comphelper::SolarMutex* pSolarMutex )
@short return a reference to shared mutex member
@descr Sometimes we need a osl-mutex for sharing with our uno helper ...
What can we do?
a) If we have an initialized "own mutex" ... we can use it!
b) Otherwhise we must use a different mutex member :-(
We must use a different mutex member :-(
I HOPE IT WORKS!
@seealso -
@@ -446,72 +302,12 @@ LockHelper& LockHelper::getGlobalLock( comphelper::SolarMutex* pSolarMutex )
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( m_pShareableOslMutex == NULL )
{
switch( m_eLockType )
{
case E_OWNMUTEX : {
m_pShareableOslMutex = m_pOwnMutex;
}
break;
default : {
m_pShareableOslMutex = new ::osl::Mutex;
}
break;
}
m_pShareableOslMutex = new ::osl::Mutex;
}
}
return *m_pShareableOslMutex;
}
/*-************************************************************************************************************//**
@short search for right lock type, which should be used by an instance of this struct
@descr We must initialize our member "m_eLockType". This value specify handling of locking.
How we can do that? We search for an environment variable. We do it only for one time ....
because the environment is fix. So we safe this value and use it for all further requests.
If no variable could be found - we use a fallback!
@attention We have numbered all our enum values for ELockType. So we can use it as value of searched
environment variable too!
@seealso enum ELockType
@seealso environment LOCKTYPE
@param -
@return A reference to a created and right initialized lock type!
@onerror We use a fallback!
*//*-*************************************************************************************************************/
ELockType& LockHelper::implts_getLockType()
{
// Initialize static "member" only for one time!
// Algorithm:
// a) Start with an invalid variable (NULL pointer)
// b) If these method first called (value not already exist!) ...
// c) ... we must create a new one. Protect follow code with the global mutex -
// (It must be - we create a static variable!)
// d) Check pointer again - because ... another instance of our class could be faster then these one!
// e) Create the new static variable, get value from the environment and set it
// f) Return new created or already existing static variable.
static ELockType* pType = NULL;
if( pType == NULL )
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( pType == NULL )
{
static ELockType eType = FALLBACK_LOCKTYPE;
OUString aEnvVar( ENVVAR_LOCKTYPE );
OUString sValue ;
if( osl_getEnvironment( aEnvVar.pData, &sValue.pData ) == osl_Process_E_None )
{
eType = (ELockType)(sValue.toInt32());
}
pType = &eType;
}
}
return *pType;
}
} // namespace framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */