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 /ucbhelper | |
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 'ucbhelper')
-rw-r--r-- | ucbhelper/source/provider/resultset.cxx | 16 | ||||
-rw-r--r-- | ucbhelper/source/provider/resultsethelper.cxx | 6 |
2 files changed, 12 insertions, 10 deletions
diff --git a/ucbhelper/source/provider/resultset.cxx b/ucbhelper/source/provider/resultset.cxx index 162f32cffabf..c3565b1179f0 100644 --- a/ucbhelper/source/provider/resultset.cxx +++ b/ucbhelper/source/provider/resultset.cxx @@ -236,7 +236,7 @@ void SAL_CALL ResultSet::dispose() { std::unique_lock aGuard( m_pImpl->m_aMutex ); - if ( m_pImpl->m_aDisposeEventListeners.getLength() ) + if ( m_pImpl->m_aDisposeEventListeners.getLength(aGuard) ) { lang::EventObject aEvt; aEvt.Source = static_cast< lang::XComponent * >( this ); @@ -262,7 +262,7 @@ void SAL_CALL ResultSet::addEventListener( { std::unique_lock aGuard( m_pImpl->m_aMutex ); - m_pImpl->m_aDisposeEventListeners.addInterface( Listener ); + m_pImpl->m_aDisposeEventListeners.addInterface( aGuard, Listener ); } @@ -272,7 +272,7 @@ void SAL_CALL ResultSet::removeEventListener( { std::unique_lock aGuard( m_pImpl->m_aMutex ); - m_pImpl->m_aDisposeEventListeners.removeInterface( Listener ); + m_pImpl->m_aDisposeEventListeners.removeInterface( aGuard, Listener ); } @@ -1256,7 +1256,7 @@ void SAL_CALL ResultSet::addPropertyChangeListener( m_pImpl->m_pPropertyChangeListeners.reset( new PropertyChangeListeners()); - m_pImpl->m_pPropertyChangeListeners->addInterface( + m_pImpl->m_pPropertyChangeListeners->addInterface(aGuard, aPropertyName, xListener ); } @@ -1274,7 +1274,7 @@ void SAL_CALL ResultSet::removePropertyChangeListener( throw beans::UnknownPropertyException(aPropertyName); if ( m_pImpl->m_pPropertyChangeListeners ) - m_pImpl->m_pPropertyChangeListeners->removeInterface( + m_pImpl->m_pPropertyChangeListeners->removeInterface(aGuard, aPropertyName, xListener ); } @@ -1303,6 +1303,8 @@ void SAL_CALL ResultSet::removeVetoableChangeListener( void ResultSet::propertyChanged( const beans::PropertyChangeEvent& rEvt ) const { + std::unique_lock aGuard( m_pImpl->m_aMutex ); + if ( !m_pImpl->m_pPropertyChangeListeners ) return; @@ -1312,7 +1314,7 @@ void ResultSet::propertyChanged( const beans::PropertyChangeEvent& rEvt ) const rEvt.PropertyName ); if ( pPropsContainer ) { - pPropsContainer->notifyEach(&beans::XPropertyChangeListener::propertyChange, rEvt); + pPropsContainer->notifyEach(aGuard, &beans::XPropertyChangeListener::propertyChange, rEvt); } // Notify listeners interested in all properties. @@ -1320,7 +1322,7 @@ void ResultSet::propertyChanged( const beans::PropertyChangeEvent& rEvt ) const = m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() ); if ( pPropsContainer ) { - comphelper::OInterfaceIteratorHelper4 aIter( *pPropsContainer ); + comphelper::OInterfaceIteratorHelper4 aIter( aGuard, *pPropsContainer ); while ( aIter.hasMoreElements() ) { aIter.next()->propertyChange( rEvt ); diff --git a/ucbhelper/source/provider/resultsethelper.cxx b/ucbhelper/source/provider/resultsethelper.cxx index 25ead4bd8a22..6d750c82dbba 100644 --- a/ucbhelper/source/provider/resultsethelper.cxx +++ b/ucbhelper/source/provider/resultsethelper.cxx @@ -90,7 +90,7 @@ void SAL_CALL ResultSetImplHelper::dispose() { std::unique_lock aGuard( m_aMutex ); - if ( m_aDisposeEventListeners.getLength() ) + if ( m_aDisposeEventListeners.getLength(aGuard) ) { lang::EventObject aEvt; aEvt.Source = static_cast< lang::XComponent * >( this ); @@ -105,7 +105,7 @@ void SAL_CALL ResultSetImplHelper::addEventListener( { std::unique_lock aGuard( m_aMutex ); - m_aDisposeEventListeners.addInterface( Listener ); + m_aDisposeEventListeners.addInterface( aGuard, Listener ); } @@ -115,7 +115,7 @@ void SAL_CALL ResultSetImplHelper::removeEventListener( { std::unique_lock aGuard( m_aMutex ); - m_aDisposeEventListeners.removeInterface( Listener ); + m_aDisposeEventListeners.removeInterface( aGuard, Listener ); } |