sw/source/core/access/accmap.cxx | 38 ++++++++++++++++------------- unotools/source/ucbhelper/ucblockbytes.cxx | 16 +++++++----- unotools/source/ucbhelper/ucblockbytes.hxx | 15 +++++++---- 3 files changed, 41 insertions(+), 28 deletions(-)
New commits: commit 17827ea4974fce0a52d9986679223c670d9889ae Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Feb 15 15:38:39 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Feb 16 07:23:48 2023 +0000 osl::Mutex->std::mutex in UcbLockBytes Change-Id: Ia84af116b705299ff4b9070f145e149c1a8a2c47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147101 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/unotools/source/ucbhelper/ucblockbytes.cxx b/unotools/source/ucbhelper/ucblockbytes.cxx index 83ef4f75ad0a..ad5289f9310f 100644 --- a/unotools/source/ucbhelper/ucblockbytes.cxx +++ b/unotools/source/ucbhelper/ucblockbytes.cxx @@ -978,35 +978,39 @@ UcbLockBytes::~UcbLockBytes() Reference < XInputStream > UcbLockBytes::getInputStream() { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); m_bDontClose = true; return m_xInputStream; } void UcbLockBytes::setStream( const Reference<XStream>& aStream ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( aStream.is() ) { m_xOutputStream = aStream->getOutputStream(); - setInputStream( aStream->getInputStream(), false ); + setInputStreamImpl( aGuard, aStream->getInputStream(), false ); m_xSeekable.set( aStream, UNO_QUERY ); } else { m_xOutputStream.clear(); - setInputStream( Reference < XInputStream >() ); + setInputStreamImpl( aGuard, Reference < XInputStream >() ); } } bool UcbLockBytes::setInputStream( const Reference<XInputStream> &rxInputStream, bool bSetXSeekable ) +{ + std::unique_lock aGuard( m_aMutex ); + return setInputStreamImpl(aGuard, rxInputStream, bSetXSeekable); +} + +bool UcbLockBytes::setInputStreamImpl( std::unique_lock<std::mutex>& /*rGuard*/, const Reference<XInputStream> &rxInputStream, bool bSetXSeekable ) { bool bRet = false; try { - osl::MutexGuard aGuard( m_aMutex ); - if ( !m_bDontClose && m_xInputStream.is() ) m_xInputStream->closeInput(); diff --git a/unotools/source/ucbhelper/ucblockbytes.hxx b/unotools/source/ucbhelper/ucblockbytes.hxx index 67a2d6216316..d866015b250f 100644 --- a/unotools/source/ucbhelper/ucblockbytes.hxx +++ b/unotools/source/ucbhelper/ucblockbytes.hxx @@ -21,9 +21,9 @@ #include <com/sun/star/uno/Reference.hxx> #include <osl/conditn.hxx> -#include <osl/mutex.hxx> #include <tools/stream.hxx> #include <comphelper/errcode.hxx> +#include <mutex> namespace com { @@ -63,7 +63,7 @@ class UcbLockBytes : public SvLockBytes { osl::Condition m_aInitialized; osl::Condition m_aTerminated; - osl::Mutex m_aMutex; + std::mutex m_aMutex; css::uno::Reference < css::io::XInputStream > m_xInputStream; css::uno::Reference < css::io::XOutputStream > m_xOutputStream; @@ -112,19 +112,19 @@ public: css::uno::Reference < css::io::XInputStream > getInputStream() const { - osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); + std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); return m_xInputStream; } css::uno::Reference < css::io::XOutputStream > getOutputStream() const { - osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); + std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); return m_xOutputStream; } css::uno::Reference < css::io::XSeekable > getSeekable() const { - osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); + std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); return m_xSeekable; } @@ -132,6 +132,11 @@ public: { m_bDontClose = true; } void SetStreamValid(); + +private: + bool setInputStreamImpl( std::unique_lock<std::mutex>& rGuard, + const css::uno::Reference < css::io::XInputStream > &rxInputStream, + bool bSetXSeekable = true ); }; } commit e8bb6e555cb4579ece3a9627d19a0a324620568a Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Feb 15 19:08:40 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Feb 16 07:23:38 2023 +0000 osl::Mutex->std::mutex in SwDrawModellListener_Impl Change-Id: I150ac67a3f053046a6d6a7cd79323fa4595078c3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147105 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx index 13fcbe6a4be1..46c0dbaf0714 100644 --- a/sw/source/core/access/accmap.cxx +++ b/sw/source/core/access/accmap.cxx @@ -64,7 +64,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/document/XShapeEventBroadcaster.hpp> #include <cppuhelper/implbase.hxx> -#include <comphelper/interfacecontainer3.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <pagepreviewlayout.hxx> #include <dcontact.hxx> #include <svx/svdmark.hxx> @@ -120,8 +120,8 @@ namespace { class SwDrawModellListener_Impl : public SfxListener, public ::cppu::WeakImplHelper< document::XShapeEventBroadcaster > { - mutable ::osl::Mutex maListenerMutex; - ::comphelper::OInterfaceContainerHelper3<css::document::XEventListener> maEventListeners; + mutable std::mutex maListenerMutex; + ::comphelper::OInterfaceContainerHelper4<css::document::XEventListener> maEventListeners; std::unordered_multimap<css::uno::Reference< css::drawing::XShape >, css::uno::Reference< css::document::XShapeEventListener >> maShapeListeners; SdrModel *mpDrawModel; protected: @@ -144,7 +144,6 @@ public: } SwDrawModellListener_Impl::SwDrawModellListener_Impl( SdrModel *pDrawModel ) : - maEventListeners( maListenerMutex ), mpDrawModel( pDrawModel ) { StartListening( *mpDrawModel ); @@ -157,12 +156,14 @@ SwDrawModellListener_Impl::~SwDrawModellListener_Impl() void SAL_CALL SwDrawModellListener_Impl::addEventListener( const uno::Reference< document::XEventListener >& xListener ) { - maEventListeners.addInterface( xListener ); + std::unique_lock g(maListenerMutex); + maEventListeners.addInterface( g, xListener ); } void SAL_CALL SwDrawModellListener_Impl::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) { - maEventListeners.removeInterface( xListener ); + std::unique_lock g(maListenerMutex); + maEventListeners.removeInterface( g, xListener ); } void SAL_CALL SwDrawModellListener_Impl::addShapeEventListener( @@ -170,7 +171,7 @@ void SAL_CALL SwDrawModellListener_Impl::addShapeEventListener( const uno::Reference< document::XShapeEventListener >& xListener ) { assert(xShape.is() && "no shape?"); - osl::MutexGuard aGuard(maListenerMutex); + std::unique_lock aGuard(maListenerMutex); maShapeListeners.emplace(xShape, xListener); } @@ -178,7 +179,7 @@ void SAL_CALL SwDrawModellListener_Impl::removeShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const uno::Reference< document::XShapeEventListener >& xListener ) { - osl::MutexGuard aGuard(maListenerMutex); + std::unique_lock aGuard(maListenerMutex); auto [itBegin, itEnd] = maShapeListeners.equal_range(xShape); for (auto it = itBegin; it != itEnd; ++it) if (it->second == xListener) @@ -212,16 +213,19 @@ void SwDrawModellListener_Impl::Notify( SfxBroadcaster& /*rBC*/, if( !SvxUnoDrawMSFactory::createEvent( mpDrawModel, pSdrHint, aEvent ) ) return; - ::comphelper::OInterfaceIteratorHelper3 aIter( maEventListeners ); - while( aIter.hasMoreElements() ) { - try + std::unique_lock g(maListenerMutex); + ::comphelper::OInterfaceIteratorHelper4 aIter( g, maEventListeners ); + while( aIter.hasMoreElements() ) { - aIter.next()->notifyEvent( aEvent ); - } - catch( uno::RuntimeException const & ) - { - TOOLS_WARN_EXCEPTION("sw.a11y", "Runtime exception caught while notifying shape"); + try + { + aIter.next()->notifyEvent( aEvent ); + } + catch( uno::RuntimeException const & ) + { + TOOLS_WARN_EXCEPTION("sw.a11y", "Runtime exception caught while notifying shape"); + } } } @@ -230,7 +234,7 @@ void SwDrawModellListener_Impl::Notify( SfxBroadcaster& /*rBC*/, { auto pSdrObject = const_cast<SdrObject*>(pSdrHint->GetObject()); uno::Reference<drawing::XShape> xShape(pSdrObject->getUnoShape(), uno::UNO_QUERY); - osl::MutexGuard aGuard(maListenerMutex); + std::unique_lock aGuard(maListenerMutex); auto [itBegin, itEnd] = maShapeListeners.equal_range(xShape); for (auto it = itBegin; it != itEnd; ++it) it->second->notifyShapeEvent(aEvent);