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:
@@ -30,23 +30,6 @@
|
|||||||
|
|
||||||
namespace framework{
|
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
|
@short helper to set right lock in right situation
|
||||||
@descr This helper support different types of locking:
|
@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 );
|
static LockHelper& getGlobalLock ( comphelper::SolarMutex* pSolarMutex = NULL );
|
||||||
::osl::Mutex& getShareableOslMutex( );
|
::osl::Mutex& getShareableOslMutex( );
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
|
||||||
// private methods
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
|
||||||
private:
|
|
||||||
|
|
||||||
static ELockType& implts_getLockType();
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
// private member
|
// private member
|
||||||
// a) Make some member mutable for using in const functions!
|
// 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.
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ELockType m_eLockType ;
|
|
||||||
|
|
||||||
mutable FairRWLock* m_pFairRWLock ;
|
|
||||||
mutable ::osl::Mutex* m_pOwnMutex ;
|
|
||||||
mutable comphelper::SolarMutex* m_pSolarMutex ;
|
mutable comphelper::SolarMutex* m_pSolarMutex ;
|
||||||
mutable ::osl::Mutex* m_pShareableOslMutex ;
|
mutable ::osl::Mutex* m_pShareableOslMutex ;
|
||||||
mutable sal_Bool m_bDummySolarMutex ;
|
mutable sal_Bool m_bDummySolarMutex ;
|
||||||
|
@@ -30,11 +30,7 @@ namespace framework{
|
|||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@short use ctor to initialize instance
|
@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 ReadGuard
|
||||||
@seealso class WriteGuard
|
@seealso class WriteGuard
|
||||||
|
|
||||||
@@ -45,39 +41,18 @@ namespace framework{
|
|||||||
@onerror -
|
@onerror -
|
||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
LockHelper::LockHelper( comphelper::SolarMutex* pSolarMutex )
|
LockHelper::LockHelper( comphelper::SolarMutex* pSolarMutex )
|
||||||
: m_pFairRWLock ( NULL )
|
: m_pSolarMutex ( NULL )
|
||||||
, m_pOwnMutex ( NULL )
|
|
||||||
, m_pSolarMutex ( NULL )
|
|
||||||
, m_pShareableOslMutex( NULL )
|
, m_pShareableOslMutex( NULL )
|
||||||
, m_bDummySolarMutex ( sal_False )
|
, m_bDummySolarMutex ( sal_False )
|
||||||
{
|
{
|
||||||
m_eLockType = implts_getLockType();
|
if( pSolarMutex == NULL )
|
||||||
switch( m_eLockType )
|
|
||||||
{
|
{
|
||||||
case E_NOTHING : break; // There is nothing to do ...
|
m_pSolarMutex = new ::vcl::SolarMutexObject;
|
||||||
case E_OWNMUTEX : {
|
m_bDummySolarMutex = sal_True;
|
||||||
m_pOwnMutex = new ::osl::Mutex;
|
}
|
||||||
}
|
else
|
||||||
break;
|
{
|
||||||
case E_SOLARMUTEX : {
|
m_pSolarMutex = pSolarMutex;
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,20 +72,9 @@ LockHelper::~LockHelper()
|
|||||||
{
|
{
|
||||||
if( m_pShareableOslMutex != NULL )
|
if( m_pShareableOslMutex != NULL )
|
||||||
{
|
{
|
||||||
// Sometimes we hold two pointer to same object!
|
delete m_pShareableOslMutex;
|
||||||
// (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;
|
|
||||||
}
|
|
||||||
m_pShareableOslMutex = NULL;
|
m_pShareableOslMutex = NULL;
|
||||||
}
|
}
|
||||||
if( m_pOwnMutex != NULL )
|
|
||||||
{
|
|
||||||
delete m_pOwnMutex;
|
|
||||||
m_pOwnMutex = NULL;
|
|
||||||
}
|
|
||||||
if( m_pSolarMutex != NULL )
|
if( m_pSolarMutex != NULL )
|
||||||
{
|
{
|
||||||
if (m_bDummySolarMutex)
|
if (m_bDummySolarMutex)
|
||||||
@@ -120,11 +84,6 @@ LockHelper::~LockHelper()
|
|||||||
}
|
}
|
||||||
m_pSolarMutex = NULL;
|
m_pSolarMutex = NULL;
|
||||||
}
|
}
|
||||||
if( m_pFairRWLock != NULL )
|
|
||||||
{
|
|
||||||
delete m_pFairRWLock;
|
|
||||||
m_pFairRWLock = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -146,22 +105,7 @@ LockHelper::~LockHelper()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::acquire()
|
void LockHelper::acquire()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->acquire();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -183,22 +127,7 @@ void LockHelper::acquire()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::release()
|
void LockHelper::release()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->release();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -206,7 +135,6 @@ void LockHelper::release()
|
|||||||
@short set lock for reading
|
@short set lock for reading
|
||||||
@descr A guard should call this method to acquire read access on your member.
|
@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!
|
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!
|
@attention If a shareable osl mutex exist, he must be used as twice!
|
||||||
It's neccessary for some cppu-helper classes ...
|
It's neccessary for some cppu-helper classes ...
|
||||||
@@ -220,29 +148,13 @@ void LockHelper::release()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::acquireReadAccess()
|
void LockHelper::acquireReadAccess()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->acquire();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@interface IRWLock
|
@interface IRWLock
|
||||||
@short reset lock for reading
|
@short reset lock for reading
|
||||||
@descr A guard should call this method to release read access on your member.
|
@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!
|
@attention If a shareable osl mutex exist, he must be used as twice!
|
||||||
It's neccessary for some cppu-helper classes ...
|
It's neccessary for some cppu-helper classes ...
|
||||||
@@ -256,22 +168,7 @@ void LockHelper::acquireReadAccess()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::releaseReadAccess()
|
void LockHelper::releaseReadAccess()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->release();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -280,7 +177,6 @@ void LockHelper::releaseReadAccess()
|
|||||||
@descr A guard should call this method to acquire write access on your member.
|
@descr A guard should call this method to acquire write access on your member.
|
||||||
Reading is allowed too - of course.
|
Reading is allowed too - of course.
|
||||||
After successfully calling of this method you are the only writer.
|
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!
|
@attention If a shareable osl mutex exist, he must be used as twice!
|
||||||
It's neccessary for some cppu-helper classes ...
|
It's neccessary for some cppu-helper classes ...
|
||||||
@@ -294,29 +190,13 @@ void LockHelper::releaseReadAccess()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::acquireWriteAccess()
|
void LockHelper::acquireWriteAccess()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->acquire();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@interface IRWLock
|
@interface IRWLock
|
||||||
@short reset lock for writing
|
@short reset lock for writing
|
||||||
@descr A guard should call this method to release write access on your member.
|
@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!
|
@attention If a shareable osl mutex exist, he must be used as twice!
|
||||||
It's neccessary for some cppu-helper classes ...
|
It's neccessary for some cppu-helper classes ...
|
||||||
@@ -330,22 +210,7 @@ void LockHelper::acquireWriteAccess()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::releaseWriteAccess()
|
void LockHelper::releaseWriteAccess()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pSolarMutex->release();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -353,7 +218,6 @@ void LockHelper::releaseWriteAccess()
|
|||||||
@short downgrade a write access to a read access
|
@short downgrade a write access to a read access
|
||||||
@descr A guard should call this method to change a write 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!
|
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!
|
@attention Ignore shareable mutex(!) - because this call never should release a lock completely!
|
||||||
We change a write access to a read access only.
|
We change a write access to a read access only.
|
||||||
@@ -362,7 +226,7 @@ void LockHelper::releaseWriteAccess()
|
|||||||
Results are not defined then ...
|
Results are not defined then ...
|
||||||
An upgrade can't be implemented realy ... because acquiring new access
|
An upgrade can't be implemented realy ... because acquiring new access
|
||||||
will be the same - there no differences!
|
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.
|
because, a mutex don't support it realy.
|
||||||
|
|
||||||
@seealso -
|
@seealso -
|
||||||
@@ -374,14 +238,7 @@ void LockHelper::releaseWriteAccess()
|
|||||||
*//*-*************************************************************************************************************/
|
*//*-*************************************************************************************************************/
|
||||||
void LockHelper::downgradeWriteAccess()
|
void LockHelper::downgradeWriteAccess()
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
// Not supported for mutex!
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-************************************************************************************************************//**
|
/*-************************************************************************************************************//**
|
||||||
@@ -428,8 +285,7 @@ LockHelper& LockHelper::getGlobalLock( comphelper::SolarMutex* pSolarMutex )
|
|||||||
@short return a reference to shared mutex member
|
@short return a reference to shared mutex member
|
||||||
@descr Sometimes we need a osl-mutex for sharing with our uno helper ...
|
@descr Sometimes we need a osl-mutex for sharing with our uno helper ...
|
||||||
What can we do?
|
What can we do?
|
||||||
a) If we have an initialized "own mutex" ... we can use it!
|
We must use a different mutex member :-(
|
||||||
b) Otherwhise we must use a different mutex member :-(
|
|
||||||
I HOPE IT WORKS!
|
I HOPE IT WORKS!
|
||||||
|
|
||||||
@seealso -
|
@seealso -
|
||||||
@@ -446,72 +302,12 @@ LockHelper& LockHelper::getGlobalLock( comphelper::SolarMutex* pSolarMutex )
|
|||||||
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
||||||
if( m_pShareableOslMutex == NULL )
|
if( m_pShareableOslMutex == NULL )
|
||||||
{
|
{
|
||||||
switch( m_eLockType )
|
m_pShareableOslMutex = new ::osl::Mutex;
|
||||||
{
|
|
||||||
case E_OWNMUTEX : {
|
|
||||||
m_pShareableOslMutex = m_pOwnMutex;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default : {
|
|
||||||
m_pShareableOslMutex = new ::osl::Mutex;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *m_pShareableOslMutex;
|
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
|
} // namespace framework
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user