summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-01-14 10:56:50 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-01-14 21:04:10 +0100
commita2eaf99e46f370ffb3b73828c2bdc53dc193b9a4 (patch)
tree6d08d7b5077478a92acde6dd6e7278e98a409ce1 /sc
parent49a5e69f567302633299bf6626a9d9b9544ee94b (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 'sc')
-rw-r--r--sc/source/ui/Accessibility/DrawModelBroadcaster.cxx24
1 files changed, 8 insertions, 16 deletions
diff --git a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx
index 8a4a8d437440..043aa479fdf1 100644
--- a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx
+++ b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx
@@ -40,14 +40,14 @@ ScDrawModelBroadcaster::~ScDrawModelBroadcaster()
void SAL_CALL ScDrawModelBroadcaster::addEventListener( const uno::Reference< document::XEventListener >& xListener )
{
- std::scoped_lock aGuard(maListenerMutex);
- maEventListeners.addInterface( xListener );
+ std::unique_lock aGuard(maListenerMutex);
+ maEventListeners.addInterface( aGuard, xListener );
}
void SAL_CALL ScDrawModelBroadcaster::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
{
- std::scoped_lock aGuard(maListenerMutex);
- maEventListeners.removeInterface( xListener );
+ std::unique_lock aGuard(maListenerMutex);
+ maEventListeners.removeInterface( aGuard, xListener );
}
void SAL_CALL ScDrawModelBroadcaster::addShapeEventListener(
@@ -87,20 +87,12 @@ void ScDrawModelBroadcaster::Notify( SfxBroadcaster&,
return;
std::unique_lock aGuard(maListenerMutex);
- ::comphelper::OInterfaceIteratorHelper4 aIter( maEventListeners );
- aGuard.unlock();
- while( aIter.hasMoreElements() )
- {
- const uno::Reference < document::XEventListener >& xListener = aIter.next();
- try
- {
- xListener->notifyEvent( aEvent );
- }
- catch( const uno::RuntimeException& )
+ maEventListeners.forEach(aGuard,
+ [&aEvent](const css::uno::Reference<document::XEventListener>& xListener)
{
- TOOLS_WARN_EXCEPTION("sc.ui", "Runtime exception caught while notifying shape");
+ xListener->notifyEvent(aEvent);
}
- }
+ );
// right now, we're only handling the specific event necessary to fix this performance problem
if (pSdrHint->GetKind() == SdrHintKind::ObjectChange)