diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-23 15:27:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-24 20:30:29 +0000 |
commit | a39f5da6f621fc60df0dbdd6c5a08cae5a18763f (patch) | |
tree | f0e180f973a697c3224d5c65244fb97f4d2e8f22 /sd | |
parent | b16f5e374eb7e7199d4506eb04a3c3223dd52257 (diff) |
BaseMutex->std::mutex in SdStyleSheet
Change-Id: I9700622ac805a9e74df1701c4ece97ef960388ef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147586
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/stlsheet.hxx | 13 | ||||
-rw-r--r-- | sd/source/core/stlsheet.cxx | 71 |
2 files changed, 40 insertions, 44 deletions
diff --git a/sd/inc/stlsheet.hxx b/sd/inc/stlsheet.hxx index e830c097e990..fe1079ffd616 100644 --- a/sd/inc/stlsheet.hxx +++ b/sd/inc/stlsheet.hxx @@ -29,13 +29,14 @@ #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <comphelper/interfacecontainer4.hxx> #include <cppuhelper/interfacecontainer.h> #include <cppuhelper/implbase.hxx> -#include <cppuhelper/basemutex.hxx> #include <svl/style.hxx> #include <memory> +#include <mutex> #include "prlayout.hxx" @@ -50,7 +51,7 @@ typedef cppu::ImplInheritanceHelper< SfxUnoStyleSheet, css::util::XModifyBroadcaster, css::lang::XComponent > SdStyleSheetBase ; -class SdStyleSheet final : public SdStyleSheetBase, private ::cppu::BaseMutex +class SdStyleSheet final : public SdStyleSheetBase { public: SdStyleSheet( const OUString& rDisplayName, SfxStyleSheetBasePool& rPool, SfxStyleFamily eFamily, SfxStyleSearchBits nMask ); @@ -152,12 +153,14 @@ private: void disposing(); + mutable std::mutex m_aMutex; + bool m_bDisposed = false; + bool m_bInDispose = false; + comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> maModifyListeners; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maEventListeners; OUString msApiName; rtl::Reference< SfxStyleSheetBasePool > mxPool; - /** broadcast helper for events */ - ::cppu::OBroadcastHelper mrBHelper; - std::unique_ptr< ModifyListenerForwarder > mpModifyListenerForwarder; SdStyleSheet( const SdStyleSheet& ) = delete; diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index 96850f5b107e..71b08db448f0 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -142,10 +142,8 @@ void ModifyListenerForwarder::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& /*r SdStyleSheet::SdStyleSheet(const OUString& rDisplayName, SfxStyleSheetBasePool& _rPool, SfxStyleFamily eFamily, SfxStyleSearchBits _nMask) : SdStyleSheetBase( rDisplayName, _rPool, eFamily, _nMask) -, ::cppu::BaseMutex() , msApiName( rDisplayName ) , mxPool( &_rPool ) -, mrBHelper( m_aMutex ) { } @@ -301,12 +299,11 @@ bool SdStyleSheet::IsUsed() const if( !bResult ) { - MutexGuard aGuard( mrBHelper.rMutex ); + std::unique_lock aGuard( m_aMutex ); - cppu::OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( cppu::UnoType<XModifyListener>::get() ); - if( pContainer ) + if( maModifyListeners.getLength(aGuard) ) { - const Sequence< Reference< XInterface > > aModifyListeners( pContainer->getElements() ); + std::vector<css::uno::Reference<XModifyListener>> aModifyListeners( maModifyListeners.getElements(aGuard) ); bResult = std::any_of(aModifyListeners.begin(), aModifyListeners.end(), [](const Reference<XInterface>& rListener) { Reference< XStyle > xStyle( rListener, UNO_QUERY ); @@ -349,10 +346,8 @@ bool SdStyleSheet::IsEditable() return false; } - MutexGuard aGuard(mrBHelper.rMutex); - - auto pContainer = mrBHelper.getContainer(cppu::UnoType<XModifyListener>::get()); - return !pContainer || pContainer->getLength() <= 1; + std::unique_lock aGuard(m_aMutex); + return maModifyListeners.getLength(aGuard) <= 1; } /** @@ -736,7 +731,7 @@ void SAL_CALL SdStyleSheet::release( ) noexcept // restore reference count: osl_atomic_increment( &m_refCount ); - if (! mrBHelper.bDisposed) try + if (! m_bDisposed) try { dispose(); } @@ -745,7 +740,7 @@ void SAL_CALL SdStyleSheet::release( ) noexcept // don't break throw () TOOLS_WARN_EXCEPTION( "sd", "" ); } - OSL_ASSERT( mrBHelper.bDisposed ); + OSL_ASSERT( m_bDisposed ); SdStyleSheetBase::release(); } @@ -754,33 +749,33 @@ void SAL_CALL SdStyleSheet::release( ) noexcept void SAL_CALL SdStyleSheet::dispose( ) { { - MutexGuard aGuard(mrBHelper.rMutex); - if (mrBHelper.bDisposed || mrBHelper.bInDispose) + std::unique_lock aGuard(m_aMutex); + if (m_bDisposed || m_bInDispose) return; - mrBHelper.bInDispose = true; + m_bInDispose = true; } try { + std::unique_lock aGuard(m_aMutex); // side effect: keeping a reference to this EventObject aEvt( static_cast< OWeakObject * >( this ) ); try { - mrBHelper.aLC.disposeAndClear( aEvt ); + maModifyListeners.disposeAndClear( aGuard, aEvt ); + maEventListeners.disposeAndClear( aGuard, aEvt ); disposing(); } catch (...) { - MutexGuard aGuard2( mrBHelper.rMutex ); // bDisposed and bInDispose must be set in this order: - mrBHelper.bDisposed = true; - mrBHelper.bInDispose = false; + m_bDisposed = true; + m_bInDispose = false; throw; } - MutexGuard aGuard2( mrBHelper.rMutex ); // bDisposed and bInDispose must be set in this order: - mrBHelper.bDisposed = true; - mrBHelper.bInDispose = false; + m_bDisposed = true; + m_bInDispose = false; } catch (RuntimeException &) { @@ -809,32 +804,33 @@ void SdStyleSheet::disposing() void SAL_CALL SdStyleSheet::addEventListener( const Reference< XEventListener >& xListener ) { - ClearableMutexGuard aGuard( mrBHelper.rMutex ); - if (mrBHelper.bDisposed || mrBHelper.bInDispose) + std::unique_lock aGuard( m_aMutex ); + if (m_bDisposed || m_bInDispose) { - aGuard.clear(); + aGuard.unlock(); EventObject aEvt( static_cast< OWeakObject * >( this ) ); xListener->disposing( aEvt ); } else { - mrBHelper.addListener( cppu::UnoType<decltype(xListener)>::get(), xListener ); + maEventListeners.addInterface( aGuard, xListener ); } } void SAL_CALL SdStyleSheet::removeEventListener( const Reference< XEventListener >& xListener ) { - mrBHelper.removeListener( cppu::UnoType<decltype(xListener)>::get(), xListener ); + std::unique_lock aGuard( m_aMutex ); + maEventListeners.removeInterface( aGuard, xListener ); } // XModifyBroadcaster void SAL_CALL SdStyleSheet::addModifyListener( const Reference< XModifyListener >& xListener ) { - ClearableMutexGuard aGuard( mrBHelper.rMutex ); - if (mrBHelper.bDisposed || mrBHelper.bInDispose) + std::unique_lock aGuard( m_aMutex ); + if (m_bDisposed || m_bInDispose) { - aGuard.clear(); + aGuard.unlock(); EventObject aEvt( static_cast< OWeakObject * >( this ) ); xListener->disposing( aEvt ); } @@ -842,27 +838,24 @@ void SAL_CALL SdStyleSheet::addModifyListener( const Reference< XModifyListener { if (!mpModifyListenerForwarder) mpModifyListenerForwarder.reset( new ModifyListenerForwarder( this ) ); - mrBHelper.addListener( cppu::UnoType<XModifyListener>::get(), xListener ); + maModifyListeners.addInterface( aGuard, xListener ); } } void SAL_CALL SdStyleSheet::removeModifyListener( const Reference< XModifyListener >& xListener ) { - mrBHelper.removeListener( cppu::UnoType<XModifyListener>::get(), xListener ); + std::unique_lock aGuard( m_aMutex ); + maModifyListeners.removeInterface( aGuard, xListener ); } void SdStyleSheet::notifyModifyListener() { - MutexGuard aGuard( mrBHelper.rMutex ); + std::unique_lock aGuard( m_aMutex ); - cppu::OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( cppu::UnoType<XModifyListener>::get() ); - if( pContainer ) + if( maModifyListeners.getLength(aGuard) ) { EventObject aEvt( static_cast< OWeakObject * >( this ) ); - pContainer->forEach<XModifyListener>( - [&] (Reference<XModifyListener> const& xListener) { - return xListener->modified(aEvt); - } ); + maModifyListeners.notifyEach(aGuard, &XModifyListener::modified, aEvt); } } |