Remove newly unused framework::LockHelper class

...and make LockHelper::getGlobalLock() FWI_DLLPUBLIC again (so there's a single
such lock, not one per library).

Change-Id: I0aed77333dc93cdf1c7dd7b96620fb7a8eb3dd64
This commit is contained in:
Stephan Bergmann
2014-03-20 16:43:22 +01:00
parent 250a4e8875
commit c8239a1dd4
8 changed files with 33 additions and 198 deletions

View File

@@ -20,68 +20,20 @@
#ifndef INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
#define INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
#include <boost/noncopyable.hpp>
#include <osl/mutex.hxx>
#include <rtl/instance.hxx>
#include <sal/config.h>
#include <comphelper/solarmutex.hxx>
#include <fwidllapi.h>
namespace framework{
namespace osl { class Mutex; }
namespace framework { namespace LockHelper {
//TODO: This presumable should return the SolarMutex, though it actually returns
// some independent mutex:
struct GlobalLock: public rtl::Static<osl::Mutex, GlobalLock> {};
FWI_DLLPUBLIC osl::Mutex & getGlobalLock();
/*-************************************************************************************************************
@short helper to set right lock in right situation
@descr This helper support different types of locking:
a) no locks - transparent for user!
This could be useful for simluation or single threaded environments!
b) own mutex
An object use his own osl-mutex to be threadsafe. Useful for easy and exclusiv locking.
c) solar mutex
An object use our solar mutex and will be a part of a greater safed "threadsafe code block".
Could be useful for simulation and testing of higher modules!
d) fair rw-lock
An object use an implementation of a fair rw-lock. This increase granularity of t hreadsafe mechanism
and should be used for high performance threadsafe code!
} }
@devstatus draft
*//*-*************************************************************************************************************/
class FWI_DLLPUBLIC LockHelper : private boost::noncopyable
{
// public methods
public:
// ctor/dtor
LockHelper( comphelper::SolarMutex* pSolarMutex = NULL );
~LockHelper( );
void acquire();
void release();
// something else
::osl::Mutex& getShareableOslMutex( );
// private member
// Make some member mutable for using in const functions!
private:
mutable comphelper::SolarMutex* m_pSolarMutex ;
mutable ::osl::Mutex* m_pShareableOslMutex ;
mutable sal_Bool m_bDummySolarMutex ;
};
} // namespace framework
#endif // INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -201,7 +201,7 @@ void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
sal_Int32 nHandle, const Any& aValue )
throw( Exception, std::exception )
{
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Search for right handle ... and try to set property value.
switch( nHandle )
@@ -231,7 +231,7 @@ throw( Exception, std::exception )
void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
Any& aValue, sal_Int32 nHandle ) const
{
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Search for right handle ... and try to get property value.
switch( nHandle )
@@ -268,7 +268,7 @@ void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
if( pInfoHelper == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfoHelper == NULL )
{
@@ -294,7 +294,7 @@ throw ( RuntimeException, std::exception )
if( pInfo == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfo == NULL )
{

View File

@@ -178,7 +178,7 @@ void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcas
sal_Int32 nHandle, const Any& aValue )
throw( Exception, std::exception )
{
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Search for right handle ... and try to set property value.
switch( nHandle )
@@ -192,7 +192,7 @@ throw( Exception, std::exception )
void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
Any& aValue, sal_Int32 nHandle ) const
{
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Search for right handle ... and try to get property value.
switch( nHandle )
@@ -213,7 +213,7 @@ void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
if( pInfoHelper == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfoHelper == NULL )
{
@@ -239,7 +239,7 @@ throw ( RuntimeException, std::exception )
if( pInfo == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfo == NULL )
{

View File

@@ -80,7 +80,7 @@ HandlerCFGAccess* HandlerCache::m_pConfig = NULL;
*/
HandlerCache::HandlerCache()
{
osl::MutexGuard g(GlobalLock::get());
osl::MutexGuard g(LockHelper::getGlobalLock());
if (m_nRefCount==0)
{
@@ -101,7 +101,7 @@ HandlerCache::HandlerCache()
*/
HandlerCache::~HandlerCache()
{
osl::MutexGuard g(GlobalLock::get());
osl::MutexGuard g(LockHelper::getGlobalLock());
if( m_nRefCount==1)
{
@@ -129,7 +129,7 @@ sal_Bool HandlerCache::search( const OUString& sURL, ProtocolHandler* pReturn )
{
sal_Bool bFound = sal_False;
/* SAFE */{
osl::MutexGuard g(GlobalLock::get());
osl::MutexGuard g(LockHelper::getGlobalLock());
PatternHash::const_iterator pItem = m_pPattern->findPatternKey(sURL);
if (pItem!=m_pPattern->end())
{
@@ -153,7 +153,7 @@ sal_Bool HandlerCache::search( const css::util::URL& aURL, ProtocolHandler* pRet
void HandlerCache::takeOver(HandlerHash* pHandler, PatternHash* pPattern)
{
osl::MutexGuard g(GlobalLock::get());
osl::MutexGuard g(LockHelper::getGlobalLock());
HandlerHash* pOldHandler = m_pHandler;
PatternHash* pOldPattern = m_pPattern;

View File

@@ -17,138 +17,21 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <osl/mutex.hxx>
#include <rtl/instance.hxx>
#include <threadhelp/lockhelper.hxx>
#include <general.h>
#include <macros/generic.hxx>
#include "vcl/solarmutex.hxx"
namespace {
#include <osl/process.h>
struct GlobalLock: public rtl::Static<osl::Mutex, GlobalLock> {};
namespace framework{
/*-************************************************************************************************************
@short use ctor to initialize instance
@seealso class Guard
@param "rSolarMutex", for some components we must be "vcl-free"! So we can't work with our solar mutex
directly. User must set his reference at this instance - so we can work with it!
@return -
@onerror -
*//*-*************************************************************************************************************/
LockHelper::LockHelper( comphelper::SolarMutex* pSolarMutex )
: m_pSolarMutex ( NULL )
, m_pShareableOslMutex( NULL )
, m_bDummySolarMutex ( sal_False )
{
if( pSolarMutex == NULL )
{
m_pSolarMutex = new ::vcl::SolarMutexObject;
m_bDummySolarMutex = sal_True;
}
else
{
m_pSolarMutex = pSolarMutex;
}
}
/*-************************************************************************************************************
@short default dtor to release safed pointer
@descr We have created dynamical mutex- or lock-member ... or we hold a pointer to external objects.
We must release it!
@seealso ctor()
@param -
@return -
@onerror -
*//*-*************************************************************************************************************/
LockHelper::~LockHelper()
{
if( m_pShareableOslMutex != NULL )
{
delete m_pShareableOslMutex;
m_pShareableOslMutex = NULL;
}
if( m_pSolarMutex != NULL )
{
if (m_bDummySolarMutex)
{
delete static_cast<vcl::SolarMutexObject*>(m_pSolarMutex);
m_bDummySolarMutex = sal_False;
}
m_pSolarMutex = NULL;
}
osl::Mutex & framework::LockHelper::getGlobalLock() {
return GlobalLock::get();
}
/*-************************************************************************************************************
@short set an exclusiv lock
@descr We must match this lock call with current set lock type and used lock member.
If a mutex should be used - it will be easy ... but if a rw-lock should be used
we must simulate it as a write access!
@attention If a shareable osl mutex exist, he must be used as twice!
It's necessary for some cppu-helper classes ...
@param -
@return -
@onerror -
*//*-*************************************************************************************************************/
void LockHelper::acquire()
{
m_pSolarMutex->acquire();
}
/*-************************************************************************************************************
@short release exclusiv lock
@descr We must match this unlock call with current set lock type and used lock member.
If a mutex should be used - it will be easy ... but if a rw-lock should be used
we must simulate it as a write access!
@attention If a shareable osl mutex exist, he must be used as twice!
It's necessary for some cppu-helper classes ...
@param -
@return -
@onerror -
*//*-*************************************************************************************************************/
void LockHelper::release()
{
m_pSolarMutex->release();
}
/*-************************************************************************************************************
@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?
We must use a different mutex member :-(
I HOPE IT WORKS!
@seealso -
@param -
@return A reference to a shared mutex.
@onerror No error should occur.
*//*-*************************************************************************************************************/
::osl::Mutex& LockHelper::getShareableOslMutex()
{
if( m_pShareableOslMutex == NULL )
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( m_pShareableOslMutex == NULL )
{
m_pShareableOslMutex = new ::osl::Mutex;
}
}
return *m_pShareableOslMutex;
}
} // namespace framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -531,7 +531,7 @@ void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce)
return;
// SAFE ->
osl::ResettableMutexGuard aGlobalLock(GlobalLock::get());
osl::ResettableMutexGuard aGlobalLock(LockHelper::getGlobalLock());
if (m_nInReschedule == 0)
{

View File

@@ -1533,7 +1533,7 @@ void SAL_CALL Desktop::getFastPropertyValue( css::uno::Any& aValue ,
if( pInfoHelper == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfoHelper == NULL )
{
@@ -1581,7 +1581,7 @@ css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL Desktop::getPropert
if( pInfo == NULL )
{
// Ready for multithreading
::osl::MutexGuard aGuard( GlobalLock::get() );
::osl::MutexGuard aGuard( LockHelper::getGlobalLock() );
// Control this pointer again, another instance can be faster then these!
if( pInfo == NULL )
{

View File

@@ -2700,7 +2700,7 @@ void SAL_CALL Frame::windowShown( const css::lang::EventObject& ) throw(css::uno
if (xDesktopCheck.is())
{
/* STATIC SAFE { */
osl::ClearableMutexGuard aStaticWriteLock( GlobalLock::get() );
osl::ClearableMutexGuard aStaticWriteLock( LockHelper::getGlobalLock() );
sal_Bool bMustBeTriggered = bFirstVisibleTask;
bFirstVisibleTask = sal_False;
aStaticWriteLock.clear();
@@ -3443,7 +3443,7 @@ void Frame::impl_checkMenuCloser()
// Look for necessary actions ...
// Only if the closer state must be moved from one frame to another one
// or must be enabled/disabled at all.
osl::MutexGuard g(GlobalLock::get());
osl::MutexGuard g(LockHelper::getGlobalLock());
css::uno::Reference< css::frame::XFrame2 > xCloserFrame (m_xCloserFrame.get(), css::uno::UNO_QUERY);
if (xCloserFrame!=xNewCloserFrame)
{