diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-05-14 14:01:01 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-05-14 14:41:55 +0200 |
commit | 4af8a94a96594a91cb54bd5b11d9a2f33eca5e65 (patch) | |
tree | 197472dbe799c8b37880cbc4071920ceb074210b /framework/source | |
parent | 61ac80a6f6d1efef7e69d2ded98ae53fe8e5a156 (diff) |
Remove unused LOCKTYPE_FRAMEWORK env var override
...which means that only the E_SOLARMUTEX part of LockHelper is ever used.
Change-Id: Ibff0bda324af67c85cbd2975d308c612c66e5052
Diffstat (limited to 'framework/source')
-rw-r--r-- | framework/source/fwi/threadhelp/lockhelper.cxx | 242 |
1 files changed, 19 insertions, 223 deletions
diff --git a/framework/source/fwi/threadhelp/lockhelper.cxx b/framework/source/fwi/threadhelp/lockhelper.cxx index 900fef47d2c4..8e2c7dd61112 100644 --- a/framework/source/fwi/threadhelp/lockhelper.cxx +++ b/framework/source/fwi/threadhelp/lockhelper.cxx @@ -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: */ |