Use SolarMutexGuard directly

(both users of PropertySetHelper use a SolarMutex-based ThreadHelpBase)

Change-Id: If542914bbf33a9e81f86d654498c2af04082f31d
This commit is contained in:
Stephan Bergmann 2014-03-20 09:23:04 +01:00
parent 6771778d2e
commit 227e924bae
4 changed files with 35 additions and 51 deletions

View File

@ -70,7 +70,6 @@ class FWI_DLLPUBLIC PropertySetHelper : public css::beans::XPropertySet
// hold it weak ... otherwise this helper has to be "killed" explicitly .-) // hold it weak ... otherwise this helper has to be "killed" explicitly .-)
css::uno::WeakReference< css::uno::XInterface > m_xBroadcaster; css::uno::WeakReference< css::uno::XInterface > m_xBroadcaster;
LockHelper& m_rLock;
TransactionManager& m_rTransactionManager; TransactionManager& m_rTransactionManager;
@ -79,11 +78,6 @@ class FWI_DLLPUBLIC PropertySetHelper : public css::beans::XPropertySet
/** initialize new instance of this helper. /** initialize new instance of this helper.
*
* @param pExternalLock
* this helper must be used as a baseclass ...
* but then it should synchronize its own calls
* with the same lock then it's superclass uses.
* *
* @param pExternalTransactionManager * @param pExternalTransactionManager
* this helper must be used as a baseclass ... * this helper must be used as a baseclass ...
@ -93,7 +87,7 @@ class FWI_DLLPUBLIC PropertySetHelper : public css::beans::XPropertySet
* @param bReleaseLockOnCall * @param bReleaseLockOnCall
* see member m_bReleaseLockOnCall * see member m_bReleaseLockOnCall
*/ */
PropertySetHelper( LockHelper* pExternalLock , PropertySetHelper( osl::Mutex & mutex,
TransactionManager* pExternalTransactionManager , TransactionManager* pExternalTransactionManager ,
sal_Bool bReleaseLockOnCall ); sal_Bool bReleaseLockOnCall );

View File

@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <vcl/svapp.hxx>
#include <classes/propertysethelper.hxx> #include <classes/propertysethelper.hxx>
#include <threadhelp/transactionguard.hxx> #include <threadhelp/transactionguard.hxx>
#include <threadhelp/guard.hxx> #include <threadhelp/guard.hxx>
@ -25,13 +29,12 @@ namespace framework{
PropertySetHelper::PropertySetHelper( LockHelper* pExternalLock , PropertySetHelper::PropertySetHelper( osl::Mutex & mutex,
TransactionManager* pExternalTransactionManager , TransactionManager* pExternalTransactionManager ,
sal_Bool bReleaseLockOnCall ) sal_Bool bReleaseLockOnCall )
: m_lSimpleChangeListener(pExternalLock->getShareableOslMutex()) : m_lSimpleChangeListener(mutex)
, m_lVetoChangeListener (pExternalLock->getShareableOslMutex()) , m_lVetoChangeListener (mutex)
, m_bReleaseLockOnCall (bReleaseLockOnCall ) , m_bReleaseLockOnCall (bReleaseLockOnCall )
, m_rLock (*pExternalLock )
, m_rTransactionManager (*pExternalTransactionManager ) , m_rTransactionManager (*pExternalTransactionManager )
{ {
} }
@ -46,11 +49,8 @@ void PropertySetHelper::impl_setPropertyChangeBroadcaster(const css::uno::Refere
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aWriteLock(m_rLock);
m_xBroadcaster = xBroadcaster; m_xBroadcaster = xBroadcaster;
aWriteLock.unlock();
// <- SAFE
} }
@ -60,15 +60,13 @@ void SAL_CALL PropertySetHelper::impl_addPropertyInfo(const css::beans::Property
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aWriteLock(m_rLock);
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name);
if (pIt != m_lProps.end()) if (pIt != m_lProps.end())
throw css::beans::PropertyExistException(); throw css::beans::PropertyExistException();
m_lProps[aProperty.Name] = aProperty; m_lProps[aProperty.Name] = aProperty;
// <- SAFE
} }
@ -78,15 +76,13 @@ void SAL_CALL PropertySetHelper::impl_removePropertyInfo(const OUString& sProper
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aWriteLock(m_rLock);
PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
m_lProps.erase(pIt); m_lProps.erase(pIt);
// <- SAFE
} }
@ -99,8 +95,7 @@ void SAL_CALL PropertySetHelper::impl_disablePropertySet()
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aWriteLock(m_rLock);
css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY); css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY);
css::lang::EventObject aEvent(xThis); css::lang::EventObject aEvent(xThis);
@ -108,9 +103,6 @@ void SAL_CALL PropertySetHelper::impl_disablePropertySet()
m_lSimpleChangeListener.disposeAndClear(aEvent); m_lSimpleChangeListener.disposeAndClear(aEvent);
m_lVetoChangeListener.disposeAndClear(aEvent); m_lVetoChangeListener.disposeAndClear(aEvent);
m_lProps.free(); m_lProps.free();
aWriteLock.unlock();
// <- SAFE
} }
@ -193,7 +185,7 @@ void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aWriteLock(m_rLock); SolarMutexResettableGuard aWriteLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
@ -204,7 +196,7 @@ void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
sal_Bool bLocked = sal_True; sal_Bool bLocked = sal_True;
if (m_bReleaseLockOnCall) if (m_bReleaseLockOnCall)
{ {
aWriteLock.unlock(); aWriteLock.clear();
bLocked = sal_False; bLocked = sal_False;
// <- SAFE // <- SAFE
} }
@ -214,7 +206,7 @@ void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
if (! bLocked) if (! bLocked)
{ {
// SAFE -> // SAFE ->
aWriteLock.lock(); aWriteLock.reset();
bLocked = sal_True; bLocked = sal_True;
} }
@ -232,7 +224,7 @@ void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
if (m_bReleaseLockOnCall) if (m_bReleaseLockOnCall)
{ {
aWriteLock.unlock(); aWriteLock.clear();
bLocked = sal_False; bLocked = sal_False;
// <- SAFE // <- SAFE
} }
@ -254,7 +246,7 @@ css::uno::Any SAL_CALL PropertySetHelper::getPropertyValue(const OUString& sProp
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aReadLock(m_rLock); SolarMutexClearableGuard aReadLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
@ -263,7 +255,7 @@ css::uno::Any SAL_CALL PropertySetHelper::getPropertyValue(const OUString& sProp
css::beans::Property aPropInfo = pIt->second; css::beans::Property aPropInfo = pIt->second;
if (m_bReleaseLockOnCall) if (m_bReleaseLockOnCall)
aReadLock.unlock(); aReadLock.clear();
return impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle); return impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
} }
@ -278,13 +270,13 @@ void SAL_CALL PropertySetHelper::addPropertyChangeListener(const OUString&
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aReadLock(m_rLock); SolarMutexClearableGuard aReadLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
aReadLock.unlock(); aReadLock.clear();
// <- SAFE // <- SAFE
m_lSimpleChangeListener.addInterface(sProperty, xListener); m_lSimpleChangeListener.addInterface(sProperty, xListener);
@ -300,13 +292,13 @@ void SAL_CALL PropertySetHelper::removePropertyChangeListener(const OUString&
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aReadLock(m_rLock); SolarMutexClearableGuard aReadLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
aReadLock.unlock(); aReadLock.clear();
// <- SAFE // <- SAFE
m_lSimpleChangeListener.removeInterface(sProperty, xListener); m_lSimpleChangeListener.removeInterface(sProperty, xListener);
@ -322,13 +314,13 @@ void SAL_CALL PropertySetHelper::addVetoableChangeListener(const OUString&
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aReadLock(m_rLock); SolarMutexClearableGuard aReadLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
aReadLock.unlock(); aReadLock.clear();
// <- SAFE // <- SAFE
m_lVetoChangeListener.addInterface(sProperty, xListener); m_lVetoChangeListener.addInterface(sProperty, xListener);
@ -344,13 +336,13 @@ void SAL_CALL PropertySetHelper::removeVetoableChangeListener(const OUString&
TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
// SAFE -> // SAFE ->
Guard aReadLock(m_rLock); SolarMutexClearableGuard aReadLock;
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
aReadLock.unlock(); aReadLock.clear();
// <- SAFE // <- SAFE
m_lVetoChangeListener.removeInterface(sProperty, xListener); m_lVetoChangeListener.removeInterface(sProperty, xListener);
@ -362,8 +354,7 @@ css::uno::Sequence< css::beans::Property > SAL_CALL PropertySetHelper::getProper
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aReadLock(m_rLock);
sal_Int32 c = (sal_Int32)m_lProps.size(); sal_Int32 c = (sal_Int32)m_lProps.size();
css::uno::Sequence< css::beans::Property > lProps(c); css::uno::Sequence< css::beans::Property > lProps(c);
@ -377,7 +368,6 @@ css::uno::Sequence< css::beans::Property > SAL_CALL PropertySetHelper::getProper
} }
return lProps; return lProps;
// <- SAFE
} }
@ -387,15 +377,13 @@ css::beans::Property SAL_CALL PropertySetHelper::getPropertyByName(const OUStrin
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aReadLock(m_rLock);
PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sName); PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sName);
if (pIt == m_lProps.end()) if (pIt == m_lProps.end())
throw css::beans::UnknownPropertyException(); throw css::beans::UnknownPropertyException();
return pIt->second; return pIt->second;
// <- SAFE
} }
@ -404,14 +392,12 @@ sal_Bool SAL_CALL PropertySetHelper::hasPropertyByName(const OUString& sName)
{ {
TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS); TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
// SAFE -> SolarMutexGuard g;
Guard aReadLock(m_rLock);
PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sName); PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sName);
sal_Bool bExist = (pIt != m_lProps.end()); sal_Bool bExist = (pIt != m_lProps.end());
return bExist; return bExist;
// <- SAFE
} }
} // namespace framework } // namespace framework

View File

@ -66,6 +66,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequenceashashmap.hxx>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/queryinterface.hxx> #include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
@ -143,6 +144,7 @@ class Frame : // interfaces
// Order is necessary for right initialization of this class! // Order is necessary for right initialization of this class!
public ThreadHelpBase , public ThreadHelpBase ,
public TransactionBase , public TransactionBase ,
private cppu::BaseMutex,
public PropertySetHelper , // helper implements ThreadHelpbase, TransactionBase, XPropertySet, XPropertySetInfo public PropertySetHelper , // helper implements ThreadHelpbase, TransactionBase, XPropertySet, XPropertySetInfo
public ::cppu::OWeakObject // helper implements XInterface, XWeak public ::cppu::OWeakObject // helper implements XInterface, XWeak
{ {
@ -559,7 +561,7 @@ DEFINE_XTYPEPROVIDER_21 ( Frame
Frame::Frame( const css::uno::Reference< css::uno::XComponentContext >& xContext ) Frame::Frame( const css::uno::Reference< css::uno::XComponentContext >& xContext )
: ThreadHelpBase ( &Application::GetSolarMutex() ) : ThreadHelpBase ( &Application::GetSolarMutex() )
, TransactionBase ( ) , TransactionBase ( )
, PropertySetHelper ( &m_aLock, , PropertySetHelper ( m_aMutex,
&m_aTransactionManager, &m_aTransactionManager,
sal_False) // sal_False => dont release shared mutex on calling us! sal_False) // sal_False => dont release shared mutex on calling us!
// init member // init member

View File

@ -28,6 +28,7 @@
#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weak.hxx> #include <cppuhelper/weak.hxx>
#include <toolkit/helper/vclunohelper.hxx> #include <toolkit/helper/vclunohelper.hxx>
@ -89,6 +90,7 @@ class TabWindowService : public css::lang::XTypeProvider
, public css::lang::XComponent , public css::lang::XComponent
, public ThreadHelpBase , public ThreadHelpBase
, public TransactionBase , public TransactionBase
, private cppu::BaseMutex
, public PropertySetHelper , public PropertySetHelper
, public ::cppu::OWeakObject , public ::cppu::OWeakObject
{ {
@ -214,7 +216,7 @@ TabWindowService::TabWindowService()
// baseclasses and then members. And we need the mutex for other baseclasses !!! // baseclasses and then members. And we need the mutex for other baseclasses !!!
: ThreadHelpBase ( &Application::GetSolarMutex() ) : ThreadHelpBase ( &Application::GetSolarMutex() )
, TransactionBase ( ) , TransactionBase ( )
, PropertySetHelper ( &m_aLock , , PropertySetHelper ( m_aMutex,
&m_aTransactionManager , &m_aTransactionManager ,
sal_False ) // sal_False => dont release shared mutex on calling us! sal_False ) // sal_False => dont release shared mutex on calling us!
, OWeakObject ( ) , OWeakObject ( )