From 17827ea4974fce0a52d9986679223c670d9889ae Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 15 Feb 2023 15:38:39 +0200 Subject: 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 --- unotools/source/ucbhelper/ucblockbytes.cxx | 16 ++++++++++------ unotools/source/ucbhelper/ucblockbytes.hxx | 15 ++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) 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& 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 &rxInputStream, bool bSetXSeekable ) +{ + std::unique_lock aGuard( m_aMutex ); + return setInputStreamImpl(aGuard, rxInputStream, bSetXSeekable); +} + +bool UcbLockBytes::setInputStreamImpl( std::unique_lock& /*rGuard*/, const Reference &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 #include -#include #include #include +#include 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& rGuard, + const css::uno::Reference < css::io::XInputStream > &rxInputStream, + bool bSetXSeekable = true ); }; } -- cgit