summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-04-07 11:48:47 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-04-07 17:53:04 +0200
commit5a824268dfdd48c00f656b767b48cd12ccbdaabb (patch)
treea25f4afd3ca49cff41fc44559aedea70c82e6c7e /comphelper
parenta6186a678cd9f67359da885606b3c3983f6bdc74 (diff)
Don't use resettable/clearable guard where plain guard is enough
Also use scope where possible. This allows to limit guard scope at language level; visualises the scope clearly; and helps avoiding errors like fixed in commit 61e4437c857854b331fa01da6f39b2b3b58a800b. Change-Id: Ifeca96e2df8e8a0897770d9546b2536806275f41 Reviewed-on: https://gerrit.libreoffice.org/70376 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/container/enumhelper.cxx24
-rw-r--r--comphelper/source/misc/instancelocker.cxx14
-rw-r--r--comphelper/source/misc/numberedcollection.cxx14
-rw-r--r--comphelper/source/property/genericpropertyset.cxx2
-rw-r--r--comphelper/source/property/opropertybag.cxx63
5 files changed, 58 insertions, 59 deletions
diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx
index b62838d3b39c..41585ae24a8a 100644
--- a/comphelper/source/container/enumhelper.cxx
+++ b/comphelper/source/container/enumhelper.cxx
@@ -53,7 +53,7 @@ OEnumerationByName::~OEnumerationByName()
sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( )
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (m_xAccess.is() && m_aNames.getLength() > m_nPos)
return true;
@@ -70,7 +70,7 @@ sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( )
css::uno::Any SAL_CALL OEnumerationByName::nextElement( )
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
css::uno::Any aRes;
if (m_xAccess.is() && m_nPos < m_aNames.getLength())
@@ -91,7 +91,7 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement( )
void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& aEvent)
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (aEvent.Source == m_xAccess)
m_xAccess.clear();
@@ -100,7 +100,7 @@ void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& aEvent
void OEnumerationByName::impl_startDisposeListening()
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (m_bListening)
return;
@@ -118,7 +118,7 @@ void OEnumerationByName::impl_startDisposeListening()
void OEnumerationByName::impl_stopDisposeListening()
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (!m_bListening)
return;
@@ -150,7 +150,7 @@ OEnumerationByIndex::~OEnumerationByIndex()
sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( )
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (m_xAccess.is() && m_xAccess->getCount() > m_nPos)
return true;
@@ -167,7 +167,7 @@ sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( )
css::uno::Any SAL_CALL OEnumerationByIndex::nextElement( )
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
css::uno::Any aRes;
if (m_xAccess.is() && m_nPos < m_xAccess->getCount())
@@ -187,7 +187,7 @@ css::uno::Any SAL_CALL OEnumerationByIndex::nextElement( )
void SAL_CALL OEnumerationByIndex::disposing(const css::lang::EventObject& aEvent)
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (aEvent.Source == m_xAccess)
m_xAccess.clear();
@@ -196,7 +196,7 @@ void SAL_CALL OEnumerationByIndex::disposing(const css::lang::EventObject& aEven
void OEnumerationByIndex::impl_startDisposeListening()
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (m_bListening)
return;
@@ -214,7 +214,7 @@ void OEnumerationByIndex::impl_startDisposeListening()
void OEnumerationByIndex::impl_stopDisposeListening()
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
if (!m_bListening)
return;
@@ -243,7 +243,7 @@ OAnyEnumeration::~OAnyEnumeration()
sal_Bool SAL_CALL OAnyEnumeration::hasMoreElements( )
{
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
return (m_lItems.getLength() > m_nPos);
}
@@ -254,7 +254,7 @@ css::uno::Any SAL_CALL OAnyEnumeration::nextElement( )
if ( ! hasMoreElements())
throw css::container::NoSuchElementException();
- ::osl::ResettableMutexGuard aLock(m_aLock);
+ osl::MutexGuard aLock(m_aLock);
sal_Int32 nPos = m_nPos;
++m_nPos;
return m_lItems[nPos];
diff --git a/comphelper/source/misc/instancelocker.cxx b/comphelper/source/misc/instancelocker.cxx
index 43991cec43b1..c995499d8410 100644
--- a/comphelper/source/misc/instancelocker.cxx
+++ b/comphelper/source/misc/instancelocker.cxx
@@ -211,7 +211,7 @@ OLockListener::~OLockListener()
void OLockListener::Dispose()
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
return;
@@ -251,7 +251,7 @@ void OLockListener::Dispose()
void SAL_CALL OLockListener::disposing( const lang::EventObject& aEvent )
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
// object is disposed
if ( aEvent.Source == m_xInstance )
@@ -276,7 +276,7 @@ void SAL_CALL OLockListener::disposing( const lang::EventObject& aEvent )
void SAL_CALL OLockListener::queryClosing( const lang::EventObject& aEvent, sal_Bool )
{
// GetsOwnership parameter is always ignored, the user of the service must close the object always
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
if ( !m_bDisposed && aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_CLOSE ) )
{
try
@@ -304,7 +304,7 @@ void SAL_CALL OLockListener::queryClosing( const lang::EventObject& aEvent, sal_
void SAL_CALL OLockListener::notifyClosing( const lang::EventObject& aEvent )
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
// object is closed, no reason to listen
if ( aEvent.Source == m_xInstance )
@@ -334,7 +334,7 @@ void SAL_CALL OLockListener::notifyClosing( const lang::EventObject& aEvent )
void SAL_CALL OLockListener::queryTermination( const lang::EventObject& aEvent )
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
if ( aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_TERMINATION ) )
{
try
@@ -362,7 +362,7 @@ void SAL_CALL OLockListener::queryTermination( const lang::EventObject& aEvent )
void SAL_CALL OLockListener::notifyTermination( const lang::EventObject& aEvent )
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
// object is terminated, no reason to listen
if ( aEvent.Source == m_xInstance )
@@ -397,7 +397,7 @@ void SAL_CALL OLockListener::notifyTermination( const lang::EventObject& aEvent
void OLockListener::Init()
{
- ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_bDisposed || m_bInitialized )
return;
diff --git a/comphelper/source/misc/numberedcollection.cxx b/comphelper/source/misc/numberedcollection.cxx
index 43aa31f972ec..81533aa7b249 100644
--- a/comphelper/source/misc/numberedcollection.cxx
+++ b/comphelper/source/misc/numberedcollection.cxx
@@ -44,7 +44,7 @@ NumberedCollection::~NumberedCollection()
void NumberedCollection::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
m_xOwner = xOwner;
@@ -55,7 +55,7 @@ void NumberedCollection::setOwner(const css::uno::Reference< css::uno::XInterfac
void NumberedCollection::setUntitledPrefix(const OUString& sPrefix)
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
m_sUntitledPrefix = sPrefix;
@@ -66,7 +66,7 @@ void NumberedCollection::setUntitledPrefix(const OUString& sPrefix)
::sal_Int32 SAL_CALL NumberedCollection::leaseNumber(const css::uno::Reference< css::uno::XInterface >& xComponent)
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
if ( ! xComponent.is ())
throw css::lang::IllegalArgumentException(ERRMSG_INVALID_COMPONENT_PARAM, m_xOwner.get(), 1);
@@ -101,7 +101,7 @@ void NumberedCollection::setUntitledPrefix(const OUString& sPrefix)
void SAL_CALL NumberedCollection::releaseNumber(::sal_Int32 nNumber)
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
if (nNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
throw css::lang::IllegalArgumentException ("Special valkud INVALID_NUMBER not allowed as input parameter.", m_xOwner.get(), 1);
@@ -138,7 +138,7 @@ void SAL_CALL NumberedCollection::releaseNumber(::sal_Int32 nNumber)
void SAL_CALL NumberedCollection::releaseNumberForComponent(const css::uno::Reference< css::uno::XInterface >& xComponent)
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
if ( ! xComponent.is ())
throw css::lang::IllegalArgumentException(ERRMSG_INVALID_COMPONENT_PARAM, m_xOwner.get(), 1);
@@ -160,7 +160,7 @@ void SAL_CALL NumberedCollection::releaseNumberForComponent(const css::uno::Refe
OUString SAL_CALL NumberedCollection::getUntitledPrefix()
{
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
+ osl::MutexGuard aLock(m_aMutex);
return m_sUntitledPrefix;
@@ -195,8 +195,8 @@ OUString SAL_CALL NumberedCollection::getUntitledPrefix()
lPossibleNumbers.push_back (i);
// SYNCHRONIZED ->
- ::osl::ResettableMutexGuard aLock(m_aMutex);
{
+ osl::MutexGuard aLock(m_aMutex);
TDeadItemList lDeadItems;
for (const auto& [rComponent, rItem] : m_lComponents)
diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx
index af224f822ede..5ce75e30323a 100644
--- a/comphelper/source/property/genericpropertyset.cxx
+++ b/comphelper/source/property/genericpropertyset.cxx
@@ -117,7 +117,7 @@ void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& aPr
void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener )
{
- ResettableMutexGuard aGuard( maMutex );
+ ClearableMutexGuard aGuard( maMutex );
Reference < XPropertySetInfo > xInfo = getPropertySetInfo( );
aGuard.clear();
if ( xInfo.is() )
diff --git a/comphelper/source/property/opropertybag.cxx b/comphelper/source/property/opropertybag.cxx
index 43dfc4cfdc71..fd5807fae03f 100644
--- a/comphelper/source/property/opropertybag.cxx
+++ b/comphelper/source/property/opropertybag.cxx
@@ -208,21 +208,21 @@ namespace comphelper
if ( !( _element >>= aProperty ) )
throw IllegalArgumentException( OUString(), *this, 1 );
- ::osl::ClearableMutexGuard g( m_aMutex );
-
- // check whether the type is allowed, everything else will be checked
- // by m_aDynamicProperties
- if ( !m_aAllowedTypes.empty()
- && m_aAllowedTypes.find( aProperty.Type ) == m_aAllowedTypes.end()
- )
- throw IllegalArgumentException( OUString(), *this, 1 );
+ {
+ osl::MutexGuard g(m_aMutex);
- m_aDynamicProperties.addVoidProperty( aProperty.Name, aProperty.Type, findFreeHandle(), aProperty.Attributes );
+ // check whether the type is allowed, everything else will be checked
+ // by m_aDynamicProperties
+ if (!m_aAllowedTypes.empty()
+ && m_aAllowedTypes.find(aProperty.Type) == m_aAllowedTypes.end())
+ throw IllegalArgumentException(OUString(), *this, 1);
- // our property info is dirty
- m_pArrayHelper.reset();
+ m_aDynamicProperties.addVoidProperty(aProperty.Name, aProperty.Type, findFreeHandle(),
+ aProperty.Attributes);
- g.clear();
+ // our property info is dirty
+ m_pArrayHelper.reset();
+ }
setModified(true);
}
@@ -312,37 +312,36 @@ namespace comphelper
void SAL_CALL OPropertyBag::addProperty( const OUString& _rName, ::sal_Int16 _nAttributes, const Any& _rInitialValue )
{
- ::osl::ClearableMutexGuard g( m_aMutex );
-
- // check whether the type is allowed, everything else will be checked
- // by m_aDynamicProperties
- const Type& aPropertyType = _rInitialValue.getValueType();
- if ( _rInitialValue.hasValue()
- && !m_aAllowedTypes.empty()
- && m_aAllowedTypes.find( aPropertyType ) == m_aAllowedTypes.end()
- )
- throw IllegalTypeException( OUString(), *this );
+ {
+ osl::MutexGuard g(m_aMutex);
- m_aDynamicProperties.addProperty( _rName, findFreeHandle(), _nAttributes, _rInitialValue );
+ // check whether the type is allowed, everything else will be checked
+ // by m_aDynamicProperties
+ const Type& aPropertyType = _rInitialValue.getValueType();
+ if (_rInitialValue.hasValue() && !m_aAllowedTypes.empty()
+ && m_aAllowedTypes.find(aPropertyType) == m_aAllowedTypes.end())
+ throw IllegalTypeException(OUString(), *this);
- // our property info is dirty
- m_pArrayHelper.reset();
+ m_aDynamicProperties.addProperty(_rName, findFreeHandle(), _nAttributes,
+ _rInitialValue);
- g.clear();
+ // our property info is dirty
+ m_pArrayHelper.reset();
+ }
setModified(true);
}
void SAL_CALL OPropertyBag::removeProperty( const OUString& _rName )
{
- ::osl::ClearableMutexGuard g( m_aMutex );
-
- m_aDynamicProperties.removeProperty( _rName );
+ {
+ osl::MutexGuard g(m_aMutex);
- // our property info is dirty
- m_pArrayHelper.reset();
+ m_aDynamicProperties.removeProperty(_rName);
- g.clear();
+ // our property info is dirty
+ m_pArrayHelper.reset();
+ }
setModified(true);
}