animations/source/animcore/animcore.cxx | 6 +++-- comphelper/source/property/propshlp.cxx | 12 +++++----- framework/source/uiconfiguration/imagemanagerimpl.cxx | 3 ++ sw/source/core/access/accmap.cxx | 1 toolkit/source/controls/tree/treedatamodel.cxx | 3 -- ucbhelper/source/provider/resultset.cxx | 6 ----- vcl/source/window/dndlistenercontainer.cxx | 21 ++++++++++-------- 7 files changed, 28 insertions(+), 24 deletions(-)
New commits: commit 31e2b4746a4a5d7661c4aa8f6a4489e50982aede Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Fri May 5 21:00:24 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun May 7 08:00:46 2023 +0200 improve some usage of OInterfaceIteratorHelper4 we can drop the lock immediately after construction (since the iterator holds a thread-safe COW link to the underlying listener container) Change-Id: I08f8fa9ed7393747938572097f3c25f5f3f847fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151440 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/animations/source/animcore/animcore.cxx b/animations/source/animcore/animcore.cxx index 09a2e793b2c0..03c815021c93 100644 --- a/animations/source/animcore/animcore.cxx +++ b/animations/source/animcore/animcore.cxx @@ -2076,14 +2076,16 @@ void SAL_CALL AnimationNode::removeChangesListener( const Reference< XChangesLis void AnimationNode::fireChangeListener(std::unique_lock<std::mutex>& l) { - OInterfaceIteratorHelper4 aIterator( l, maChangeListener ); - if( aIterator.hasMoreElements() ) + if( maChangeListener.getLength(l) != 0 ) { Reference< XInterface > xSource( static_cast<OWeakObject*>(this), UNO_QUERY ); Sequence< ElementChange > aChanges; const ChangesEvent aEvent( xSource, Any( css::uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(mxParent.get().get())) ), aChanges ); + OInterfaceIteratorHelper4 aIterator( l, maChangeListener ); + l.unlock(); while( aIterator.hasMoreElements() ) aIterator.next()->changesOccurred( aEvent ); + l.lock(); } //fdo#69645 use WeakReference of mxParent to test if mpParent is still valid diff --git a/comphelper/source/property/propshlp.cxx b/comphelper/source/property/propshlp.cxx index 97b89f1aaf1d..dd227cc15e25 100644 --- a/comphelper/source/property/propshlp.cxx +++ b/comphelper/source/property/propshlp.cxx @@ -582,10 +582,10 @@ void OPropertySetHelper::fire(std::unique_lock<std::mutex>& rGuard, sal_Int32* p // Here is a Bug, unbound properties are also fired OInterfaceIteratorHelper4 aIt(rGuard, maPropertiesChangeListeners); + rGuard.unlock(); while (aIt.hasMoreElements()) { XPropertiesChangeListener* pL = aIt.next().get(); - rGuard.unlock(); try { try @@ -613,8 +613,8 @@ void OPropertySetHelper::fire(std::unique_lock<std::mutex>& rGuard, sal_Int32* p if (!bIgnoreRuntimeExceptionsWhileFiring) throw; } - rGuard.lock(); } + rGuard.lock(); } void OPropertySetHelper::fireVetoableChangeListeners( @@ -626,10 +626,10 @@ void OPropertySetHelper::fireVetoableChangeListeners( return; // Iterate over all listeners and send events OInterfaceIteratorHelper4 aIt(rGuard, *pListeners); + rGuard.unlock(); while (aIt.hasMoreElements()) { XVetoableChangeListener* pL = aIt.next().get(); - rGuard.unlock(); try { try @@ -655,8 +655,8 @@ void OPropertySetHelper::fireVetoableChangeListeners( if (!m_bIgnoreRuntimeExceptionsWhileFiring) throw; } - rGuard.lock(); } + rGuard.lock(); } void OPropertySetHelper::firePropertyChangeListeners( @@ -668,10 +668,10 @@ void OPropertySetHelper::firePropertyChangeListeners( return; // Iterate over all listeners and send events OInterfaceIteratorHelper4 aIt(rGuard, *pListeners); + rGuard.unlock(); while (aIt.hasMoreElements()) { XPropertyChangeListener* pL = aIt.next().get(); - rGuard.unlock(); try { try @@ -697,8 +697,8 @@ void OPropertySetHelper::firePropertyChangeListeners( if (!m_bIgnoreRuntimeExceptionsWhileFiring) throw; } - rGuard.lock(); } + rGuard.lock(); } // OPropertySetHelper diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index 26aa0f33400c..0152387cc0b4 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -1169,6 +1169,7 @@ void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& { std::unique_lock aGuard(m_mutex); comphelper::OInterfaceIteratorHelper4 pIterator( aGuard, m_aConfigListeners ); + aGuard.unlock(); while ( pIterator.hasMoreElements() ) { try @@ -1188,7 +1189,9 @@ void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& } catch( const css::uno::RuntimeException& ) { + aGuard.lock(); pIterator.remove(aGuard); + aGuard.unlock(); } } } diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx index 70cc1eb27929..fe0384ca0ea2 100644 --- a/sw/source/core/access/accmap.cxx +++ b/sw/source/core/access/accmap.cxx @@ -217,6 +217,7 @@ void SwDrawModellListener_Impl::Notify( SfxBroadcaster& /*rBC*/, { std::unique_lock g(maListenerMutex); ::comphelper::OInterfaceIteratorHelper4 aIter( g, maEventListeners ); + g.unlock(); while( aIter.hasMoreElements() ) { try diff --git a/toolkit/source/controls/tree/treedatamodel.cxx b/toolkit/source/controls/tree/treedatamodel.cxx index efccdd689692..d2590a361ef7 100644 --- a/toolkit/source/controls/tree/treedatamodel.cxx +++ b/toolkit/source/controls/tree/treedatamodel.cxx @@ -157,9 +157,9 @@ void MutableTreeDataModel::broadcastImpl( std::unique_lock<std::mutex>& rGuard, TreeDataModelEvent aEvent( xSource, aNodes, xParentNode ); comphelper::OInterfaceIteratorHelper4 aListIter(rGuard, maTreeDataModelListeners); + rGuard.unlock(); while(aListIter.hasMoreElements()) { - rGuard.unlock(); XTreeDataModelListener* pListener = aListIter.next().get(); switch( eType ) { @@ -168,7 +168,6 @@ void MutableTreeDataModel::broadcastImpl( std::unique_lock<std::mutex>& rGuard, case nodes_removed: pListener->treeNodesRemoved(aEvent); break; case structure_changed: pListener->treeStructureChanged(aEvent); break; } - rGuard.lock(); } } diff --git a/ucbhelper/source/provider/resultset.cxx b/ucbhelper/source/provider/resultset.cxx index 1615c72ade3c..b443a32e1b39 100644 --- a/ucbhelper/source/provider/resultset.cxx +++ b/ucbhelper/source/provider/resultset.cxx @@ -1315,11 +1315,7 @@ void ResultSet::propertyChanged( const beans::PropertyChangeEvent& rEvt ) const = m_pImpl->m_pPropertyChangeListeners->getContainer( aGuard, OUString() ); if ( pPropsContainer ) { - comphelper::OInterfaceIteratorHelper4 aIter( aGuard, *pPropsContainer ); - while ( aIter.hasMoreElements() ) - { - aIter.next()->propertyChange( rEvt ); - } + pPropsContainer->notifyEach( aGuard, &beans::XPropertyChangeListener::propertyChange, rEvt); } } diff --git a/vcl/source/window/dndlistenercontainer.cxx b/vcl/source/window/dndlistenercontainer.cxx index fdc7c40c810e..9ff128c808bb 100644 --- a/vcl/source/window/dndlistenercontainer.cxx +++ b/vcl/source/window/dndlistenercontainer.cxx @@ -107,12 +107,15 @@ sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDrop Reference< XDropTargetListener > xListener( aIterator.next() ); try { - g.unlock(); // fire drop until the first one has accepted if( m_xDropTargetDropContext.is() ) + { + g.unlock(); xListener->drop( aEvent ); + } else { + g.unlock(); DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 ); xListener->dragExit( aDTEvent ); } @@ -151,24 +154,24 @@ sal_uInt32 DNDListenerContainer::fireDragExitEvent() sal_uInt32 nRet = 0; - comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // do not construct the event before you are sure at least one listener is registered DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); + g.unlock(); while (aIterator.hasMoreElements()) { Reference< XDropTargetListener > xListener( aIterator.next() ); try { - g.unlock(); xListener->dragExit( aEvent ); nRet++; - g.lock(); } catch (const RuntimeException&) { + g.lock(); aIterator.remove( g ); + g.unlock(); } } @@ -354,25 +357,25 @@ sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_ sal_uInt32 nRet = 0; - comphelper::OInterfaceIteratorHelper4 aIterator( g, maDragGestureListeners ); - // do not construct the event before you are sure at least one listener is registered DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction, dragOriginX, dragOriginY, dragSource, triggerEvent ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDragGestureListeners ); + g.unlock(); while( aIterator.hasMoreElements() ) { Reference< XDragGestureListener > xListener( aIterator.next() ); try { - g.unlock(); xListener->dragGestureRecognized( aEvent ); - g.lock(); nRet++; } catch (const RuntimeException&) { + g.lock(); aIterator.remove( g ); + g.unlock(); } }