diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-14 10:56:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-14 21:04:10 +0100 |
commit | a2eaf99e46f370ffb3b73828c2bdc53dc193b9a4 (patch) | |
tree | 6d08d7b5077478a92acde6dd6e7278e98a409ce1 /comphelper | |
parent | 49a5e69f567302633299bf6626a9d9b9544ee94b (diff) |
make comphelper::OInterfaceContainerHelper4 more threadsafe
(*) make all the methods that require an external mutex take a
std::unique_lock as a parameter, so that call sites cannot forget
(*) make the forEach method drop the lock when firing listener methods,
to reduce the odds of deadlock
Change-Id: I0a80e3b3d1c1c03b7de4a658d31fcc2847690903
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128415
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/accessibleeventnotifier.cxx | 16 | ||||
-rw-r--r-- | comphelper/source/misc/compbase.cxx | 4 | ||||
-rw-r--r-- | comphelper/source/misc/instancelocker.cxx | 8 |
3 files changed, 14 insertions, 14 deletions
diff --git a/comphelper/source/misc/accessibleeventnotifier.cxx b/comphelper/source/misc/accessibleeventnotifier.cxx index c1e26c35bdd9..f8bd5a1170e8 100644 --- a/comphelper/source/misc/accessibleeventnotifier.cxx +++ b/comphelper/source/misc/accessibleeventnotifier.cxx @@ -209,7 +209,7 @@ void AccessibleEventNotifier::revokeClientNotifyDisposing( sal_Int32 AccessibleEventNotifier::addEventListener( const TClientId _nClient, const Reference< XAccessibleEventListener >& _rxListener ) { - std::scoped_lock aGuard( GetLocalMutex() ); + std::unique_lock aGuard( GetLocalMutex() ); ClientMap::iterator aClientPos; if ( !implLookupClient( _nClient, aClientPos ) ) @@ -217,15 +217,15 @@ sal_Int32 AccessibleEventNotifier::addEventListener( return 0; if ( _rxListener.is() ) - aClientPos->second->addInterface( _rxListener ); + aClientPos->second->addInterface( aGuard, _rxListener ); - return aClientPos->second->getLength(); + return aClientPos->second->getLength(aGuard); } sal_Int32 AccessibleEventNotifier::removeEventListener( const TClientId _nClient, const Reference< XAccessibleEventListener >& _rxListener ) { - std::scoped_lock aGuard( GetLocalMutex() ); + std::unique_lock aGuard( GetLocalMutex() ); ClientMap::iterator aClientPos; if ( !implLookupClient( _nClient, aClientPos ) ) @@ -233,9 +233,9 @@ sal_Int32 AccessibleEventNotifier::removeEventListener( return 0; if ( _rxListener.is() ) - aClientPos->second->removeInterface( _rxListener ); + aClientPos->second->removeInterface( aGuard, _rxListener ); - return aClientPos->second->getLength(); + return aClientPos->second->getLength(aGuard); } void AccessibleEventNotifier::addEvent( const TClientId _nClient, const AccessibleEventObject& _rEvent ) @@ -243,7 +243,7 @@ void AccessibleEventNotifier::addEvent( const TClientId _nClient, const Accessib std::vector< Reference< XAccessibleEventListener > > aListeners; { - std::scoped_lock aGuard( GetLocalMutex() ); + std::unique_lock aGuard( GetLocalMutex() ); ClientMap::iterator aClientPos; if ( !implLookupClient( _nClient, aClientPos ) ) @@ -251,7 +251,7 @@ void AccessibleEventNotifier::addEvent( const TClientId _nClient, const Accessib return; // since we're synchronous, again, we want to notify immediately - aListeners = aClientPos->second->getElements(); + aListeners = aClientPos->second->getElements(aGuard); } // default handling: loop through all listeners, and notify them diff --git a/comphelper/source/misc/compbase.cxx b/comphelper/source/misc/compbase.cxx index ff3c4778b2ba..f8a8897b7bb7 100644 --- a/comphelper/source/misc/compbase.cxx +++ b/comphelper/source/misc/compbase.cxx @@ -37,14 +37,14 @@ void SAL_CALL WeakComponentImplHelperBase::addEventListener( std::unique_lock aGuard(m_aMutex); if (m_bDisposed) return; - maEventListeners.addInterface(rxListener); + maEventListeners.addInterface(aGuard, rxListener); } void SAL_CALL WeakComponentImplHelperBase::removeEventListener( css::uno::Reference<css::lang::XEventListener> const& rxListener) { std::unique_lock aGuard(m_aMutex); - maEventListeners.removeInterface(rxListener); + maEventListeners.removeInterface(aGuard, rxListener); } css::uno::Any SAL_CALL WeakComponentImplHelperBase::queryInterface(css::uno::Type const& rType) diff --git a/comphelper/source/misc/instancelocker.cxx b/comphelper/source/misc/instancelocker.cxx index a24572c6c865..347ff513cb6e 100644 --- a/comphelper/source/misc/instancelocker.cxx +++ b/comphelper/source/misc/instancelocker.cxx @@ -87,18 +87,18 @@ void SAL_CALL OInstanceLocker::dispose() void SAL_CALL OInstanceLocker::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) { - std::scoped_lock aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO - m_aListenersContainer.addInterface( xListener ); + m_aListenersContainer.addInterface( aGuard, xListener ); } void SAL_CALL OInstanceLocker::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) { - std::scoped_lock aGuard( m_aMutex ); - m_aListenersContainer.removeInterface( xListener ); + std::unique_lock aGuard( m_aMutex ); + m_aListenersContainer.removeInterface( aGuard, xListener ); } // XInitialization |