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.grandin@collabora.co.uk>
This commit is contained in:
committed by
Noel Grandin
parent
50deb478e9
commit
31e2b4746a
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user