diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-08-23 21:44:56 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-25 09:10:50 +0200 |
commit | b27ede1a629ac2b5f9e98def37326d546923edec (patch) | |
tree | c3bd097378ce5107895551c6f179321ede9989be | |
parent | 400a44261c3891c1fb99b5339ada69cbc4777dd0 (diff) |
osl::Mutex->std::mutex in ResourceListener
Change-Id: Ide7073273be3405a1d78687a2d6dd12369dd226d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120955
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sc/source/ui/Accessibility/DrawModelBroadcaster.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/inc/DrawModelBroadcaster.hxx | 7 | ||||
-rw-r--r-- | toolkit/inc/controls/controlmodelcontainerbase.hxx | 5 | ||||
-rw-r--r-- | toolkit/source/controls/controlmodelcontainerbase.cxx | 34 |
4 files changed, 32 insertions, 27 deletions
diff --git a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx index aa1df4d8dd94..8a4a8d437440 100644 --- a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx +++ b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx @@ -26,7 +26,6 @@ using namespace ::com::sun::star; ScDrawModelBroadcaster::ScDrawModelBroadcaster( SdrModel *pDrawModel ) : - maEventListeners( maListenerMutex ), mpDrawModel( pDrawModel ) { if (mpDrawModel) @@ -41,11 +40,13 @@ ScDrawModelBroadcaster::~ScDrawModelBroadcaster() void SAL_CALL ScDrawModelBroadcaster::addEventListener( const uno::Reference< document::XEventListener >& xListener ) { + std::scoped_lock aGuard(maListenerMutex); maEventListeners.addInterface( xListener ); } void SAL_CALL ScDrawModelBroadcaster::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) { + std::scoped_lock aGuard(maListenerMutex); maEventListeners.removeInterface( xListener ); } @@ -54,7 +55,7 @@ void SAL_CALL ScDrawModelBroadcaster::addShapeEventListener( const uno::Reference< document::XShapeEventListener >& xListener ) { assert(xShape.is() && "no shape?"); - osl::MutexGuard aGuard(maListenerMutex); + std::scoped_lock aGuard(maListenerMutex); auto rv = maShapeListeners.emplace(xShape, xListener); assert(rv.second && "duplicate listener?"); (void)rv; @@ -64,7 +65,7 @@ void SAL_CALL ScDrawModelBroadcaster::removeShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const uno::Reference< document::XShapeEventListener >& xListener ) { - osl::MutexGuard aGuard(maListenerMutex); + std::scoped_lock aGuard(maListenerMutex); auto it = maShapeListeners.find(xShape); if (it != maShapeListeners.end()) { @@ -85,7 +86,9 @@ void ScDrawModelBroadcaster::Notify( SfxBroadcaster&, if( !SvxUnoDrawMSFactory::createEvent( mpDrawModel, pSdrHint, aEvent ) ) return; - ::comphelper::OInterfaceIteratorHelper3 aIter( maEventListeners ); + std::unique_lock aGuard(maListenerMutex); + ::comphelper::OInterfaceIteratorHelper4 aIter( maEventListeners ); + aGuard.unlock(); while( aIter.hasMoreElements() ) { const uno::Reference < document::XEventListener >& xListener = aIter.next(); @@ -104,7 +107,7 @@ void ScDrawModelBroadcaster::Notify( SfxBroadcaster&, { auto pSdrObject = const_cast<SdrObject*>(pSdrHint->GetObject()); uno::Reference<drawing::XShape> xShape(pSdrObject->getUnoShape(), uno::UNO_QUERY); - osl::MutexGuard aGuard(maListenerMutex); + aGuard.lock(); auto it = maShapeListeners.find(xShape); if (it != maShapeListeners.end()) it->second->notifyShapeEvent(aEvent); diff --git a/sc/source/ui/inc/DrawModelBroadcaster.hxx b/sc/source/ui/inc/DrawModelBroadcaster.hxx index 34d46f89b210..a4c58dbba04b 100644 --- a/sc/source/ui/inc/DrawModelBroadcaster.hxx +++ b/sc/source/ui/inc/DrawModelBroadcaster.hxx @@ -20,10 +20,11 @@ #pragma once #include <svl/lstner.hxx> -#include <comphelper/interfacecontainer3.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <cppuhelper/implbase.hxx> #include <com/sun/star/document/XEventBroadcaster.hpp> #include <com/sun/star/document/XShapeEventBroadcaster.hpp> +#include <mutex> #include <unordered_map> class SdrModel; @@ -31,8 +32,8 @@ class SdrModel; class ScDrawModelBroadcaster : public SfxListener, public ::cppu::WeakImplHelper< css::document::XShapeEventBroadcaster > { - mutable ::osl::Mutex maListenerMutex; - ::comphelper::OInterfaceContainerHelper3<css::document::XEventListener> maEventListeners; + mutable std::mutex maListenerMutex; + ::comphelper::OInterfaceContainerHelper4<css::document::XEventListener> maEventListeners; std::unordered_map<css::uno::Reference< css::drawing::XShape >, css::uno::Reference< css::document::XShapeEventListener >> maShapeListeners; SdrModel *mpDrawModel; diff --git a/toolkit/inc/controls/controlmodelcontainerbase.hxx b/toolkit/inc/controls/controlmodelcontainerbase.hxx index df5b4aac89a7..e84bb4267e42 100644 --- a/toolkit/inc/controls/controlmodelcontainerbase.hxx +++ b/toolkit/inc/controls/controlmodelcontainerbase.hxx @@ -37,6 +37,7 @@ #include <cppuhelper/basemutex.hxx> #include <com/sun/star/awt/tab/XTabPageModel.hpp> #include <com/sun/star/lang/XInitialization.hpp> +#include <mutex> #include <vector> namespace com::sun::star::resource { class XStringResourceResolver; } @@ -181,8 +182,7 @@ protected: }; class ResourceListener final : public css::util::XModifyListener, - public ::cppu::OWeakObject, - public ::cppu::BaseMutex + public ::cppu::OWeakObject { public: ResourceListener( const css::uno::Reference< css::util::XModifyListener >& xListener ); @@ -203,6 +203,7 @@ class ResourceListener final : public css::util::XModifyListener, virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; private: + std::mutex m_aMutex; css::uno::Reference< css::resource::XStringResourceResolver > m_xResource; css::uno::Reference< css::util::XModifyListener > m_xListener; bool m_bListening; diff --git a/toolkit/source/controls/controlmodelcontainerbase.cxx b/toolkit/source/controls/controlmodelcontainerbase.cxx index 62453331474b..2731423fdf5e 100644 --- a/toolkit/source/controls/controlmodelcontainerbase.cxx +++ b/toolkit/source/controls/controlmodelcontainerbase.cxx @@ -1084,19 +1084,19 @@ void ResourceListener::startListening( { { // --- SAFE --- - ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); bool bListening( m_bListening ); bool bResourceSet( m_xResource.is() ); - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- if ( bListening && bResourceSet ) stopListening(); // --- SAFE --- - aGuard.reset(); + aGuard.lock(); m_xResource = rResource; - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- } @@ -1108,7 +1108,7 @@ void ResourceListener::startListening( rResource->addModifyListener( this ); // --- SAFE --- - ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + std::scoped_lock aGuard( m_aMutex ); m_bListening = true; // --- SAFE --- } @@ -1126,10 +1126,10 @@ void ResourceListener::stopListening() Reference< util::XModifyBroadcaster > xModifyBroadcaster; // --- SAFE --- - ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( m_bListening && m_xResource.is() ) xModifyBroadcaster = m_xResource; - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- if ( !xModifyBroadcaster.is() ) @@ -1138,10 +1138,10 @@ void ResourceListener::stopListening() try { // --- SAFE --- - aGuard.reset(); + aGuard.lock(); m_bListening = false; m_xResource.clear(); - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- xModifyBroadcaster->removeModifyListener( this ); @@ -1162,9 +1162,9 @@ void SAL_CALL ResourceListener::modified( Reference< util::XModifyListener > xListener; // --- SAFE --- - ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); xListener = m_xListener; - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- if ( !xListener.is() ) @@ -1191,21 +1191,21 @@ void SAL_CALL ResourceListener::disposing( Reference< resource::XStringResourceResolver > xResource; // --- SAFE --- - ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); Reference< XInterface > xIfacRes( m_xResource, UNO_QUERY ); Reference< XInterface > xIfacList( m_xListener, UNO_QUERY ); - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- if ( Source.Source == xIfacRes ) { // --- SAFE --- - aGuard.reset(); + aGuard.lock(); m_bListening = false; xResource = m_xResource; xListener = m_xListener; m_xResource.clear(); - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- if ( xListener.is() ) @@ -1226,13 +1226,13 @@ void SAL_CALL ResourceListener::disposing( else if ( Source.Source == xIfacList ) { // --- SAFE --- - aGuard.reset(); + aGuard.lock(); m_bListening = false; xListener = m_xListener; xResource = m_xResource; m_xResource.clear(); m_xListener.clear(); - aGuard.clear(); + aGuard.unlock(); // --- SAFE --- // Remove ourself as listener from resource resolver |