summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-08-22 14:59:52 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-23 14:30:42 +0200
commitb788e6e8fd4debbb38a03c374929b6af4678d7e5 (patch)
tree9c17b849ffffebeadfe835b7724cd8722a20f32f /comphelper
parent3a9167e1b8a236da2862f4377e2040a8c189c99c (diff)
osl::Mutex->std::mutex in AccessibleEventNotifier
which means we need a new interface container to handle std::mutex. Take the opportunity to move most of the locking outside the InterfaceContainer class to make it easier for other osl::Mutex->std::mutex conversions. Change-Id: I5dbd84aa9b7fd9c5e6058d23b993b732f61fbd20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120846 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/accessibleeventnotifier.cxx65
1 files changed, 27 insertions, 38 deletions
diff --git a/comphelper/source/misc/accessibleeventnotifier.cxx b/comphelper/source/misc/accessibleeventnotifier.cxx
index d2694ab6120b..c1e26c35bdd9 100644
--- a/comphelper/source/misc/accessibleeventnotifier.cxx
+++ b/comphelper/source/misc/accessibleeventnotifier.cxx
@@ -19,7 +19,7 @@
#include <comphelper/accessibleeventnotifier.hxx>
#include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
-#include <comphelper/interfacecontainer2.hxx>
+#include <comphelper/interfacecontainer4.hxx>
#include <map>
#include <memory>
@@ -35,16 +35,16 @@ namespace {
typedef std::pair< AccessibleEventNotifier::TClientId,
AccessibleEventObject > ClientEvent;
-typedef std::map< AccessibleEventNotifier::TClientId,
- ::comphelper::OInterfaceContainerHelper2* > ClientMap;
+typedef ::comphelper::OInterfaceContainerHelper4<XAccessibleEventListener> ListenerContainer;
+typedef std::map< AccessibleEventNotifier::TClientId, ListenerContainer* > ClientMap;
/// key is the end of the interval, value is the start of the interval
typedef std::map<AccessibleEventNotifier::TClientId,
AccessibleEventNotifier::TClientId> IntervalMap;
-::osl::Mutex& GetLocalMutex()
+std::mutex& GetLocalMutex()
{
- static ::osl::Mutex MUTEX;
+ static std::mutex MUTEX;
return MUTEX;
}
@@ -149,19 +149,13 @@ namespace comphelper {
AccessibleEventNotifier::TClientId AccessibleEventNotifier::registerClient()
{
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::scoped_lock aGuard( GetLocalMutex() );
// generate a new client id
TClientId nNewClientId = generateId( );
// the event listeners for the new client
- ::comphelper::OInterfaceContainerHelper2 *const pNewListeners =
- new ::comphelper::OInterfaceContainerHelper2( GetLocalMutex() );
- // note that we're using our own mutex here, so the listener containers for all
- // our clients share this same mutex.
- // this is a reminiscence to the days where the notifier was asynchronous. Today this is
- // completely nonsense, and potentially slowing down the Office me thinks...
-
+ ListenerContainer * pNewListeners = new ListenerContainer();
// add the client
gaClients.emplace( nNewClientId, pNewListeners );
@@ -171,7 +165,7 @@ AccessibleEventNotifier::TClientId AccessibleEventNotifier::registerClient()
void AccessibleEventNotifier::revokeClient( const TClientId _nClient )
{
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::scoped_lock aGuard( GetLocalMutex() );
ClientMap::iterator aClientPos;
if ( !implLookupClient( _nClient, aClientPos ) )
@@ -187,40 +181,35 @@ void AccessibleEventNotifier::revokeClient( const TClientId _nClient )
void AccessibleEventNotifier::revokeClientNotifyDisposing(
const TClientId _nClient, const Reference< XInterface >& _rxEventSource )
{
- std::unique_ptr<::comphelper::OInterfaceContainerHelper2> pListeners;
-
- {
- // rhbz#1001768 drop the mutex before calling disposeAndClear
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::unique_lock aGuard( GetLocalMutex() );
- ClientMap::iterator aClientPos;
- if (!implLookupClient(_nClient, aClientPos))
- // already asserted in implLookupClient
- return;
+ ClientMap::iterator aClientPos;
+ if (!implLookupClient(_nClient, aClientPos))
+ // already asserted in implLookupClient
+ return;
- // notify the listeners
- pListeners.reset(aClientPos->second);
+ // notify the listeners
+ std::unique_ptr<ListenerContainer> pListeners(aClientPos->second);
- // we do not need the entry in the clients map anymore
- // (do this before actually notifying, because some client
- // implementations have re-entrance problems and call into
- // revokeClient while we are notifying from here)
- gaClients.erase(aClientPos);
- releaseId(_nClient);
- }
+ // we do not need the entry in the clients map anymore
+ // (do this before actually notifying, because some client
+ // implementations have re-entrance problems and call into
+ // revokeClient while we are notifying from here)
+ gaClients.erase(aClientPos);
+ releaseId(_nClient);
// notify the "disposing" event for this client
EventObject aDisposalEvent;
aDisposalEvent.Source = _rxEventSource;
// now really do the notification
- pListeners->disposeAndClear( aDisposalEvent );
+ pListeners->disposeAndClear( aGuard, aDisposalEvent );
}
sal_Int32 AccessibleEventNotifier::addEventListener(
const TClientId _nClient, const Reference< XAccessibleEventListener >& _rxListener )
{
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::scoped_lock aGuard( GetLocalMutex() );
ClientMap::iterator aClientPos;
if ( !implLookupClient( _nClient, aClientPos ) )
@@ -236,7 +225,7 @@ sal_Int32 AccessibleEventNotifier::addEventListener(
sal_Int32 AccessibleEventNotifier::removeEventListener(
const TClientId _nClient, const Reference< XAccessibleEventListener >& _rxListener )
{
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::scoped_lock aGuard( GetLocalMutex() );
ClientMap::iterator aClientPos;
if ( !implLookupClient( _nClient, aClientPos ) )
@@ -251,10 +240,10 @@ sal_Int32 AccessibleEventNotifier::removeEventListener(
void AccessibleEventNotifier::addEvent( const TClientId _nClient, const AccessibleEventObject& _rEvent )
{
- std::vector< Reference< XInterface > > aListeners;
+ std::vector< Reference< XAccessibleEventListener > > aListeners;
{
- ::osl::MutexGuard aGuard( GetLocalMutex() );
+ std::scoped_lock aGuard( GetLocalMutex() );
ClientMap::iterator aClientPos;
if ( !implLookupClient( _nClient, aClientPos ) )
@@ -270,7 +259,7 @@ void AccessibleEventNotifier::addEvent( const TClientId _nClient, const Accessib
{
try
{
- static_cast< XAccessibleEventListener* >( rListener.get() )->notifyEvent( _rEvent );
+ rListener->notifyEvent( _rEvent );
}
catch( const Exception& )
{