[Libreoffice-commits] core.git: svl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 24 06:40:01 UTC 2021


 svl/source/fsstor/ostreamcontainer.cxx |  102 ++++++++++++++++-----------------
 svl/source/fsstor/ostreamcontainer.hxx |    8 +-
 2 files changed, 54 insertions(+), 56 deletions(-)

New commits:
commit a19d84ca25827d1fbe0ab9b276eeff843546ec87
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Aug 22 18:47:35 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Aug 24 08:39:19 2021 +0200

    osl::Mutex->std::mutex in OFSStreamContainer
    
    Change-Id: I1402b66935c0229977357d0a6ec8ed0bc777de3e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120904
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svl/source/fsstor/ostreamcontainer.cxx b/svl/source/fsstor/ostreamcontainer.cxx
index e5ec14fd9388..99b8afb1e9c0 100644
--- a/svl/source/fsstor/ostreamcontainer.cxx
+++ b/svl/source/fsstor/ostreamcontainer.cxx
@@ -137,7 +137,7 @@ uno::Sequence< uno::Type > SAL_CALL OFSStreamContainer::getTypes()
 {
     if ( !m_aTypes.hasElements() )
     {
-        ::osl::MutexGuard aGuard( m_aMutex );
+        std::scoped_lock aGuard( m_aMutex );
 
         if ( !m_aTypes.hasElements() )
         {
@@ -170,7 +170,7 @@ uno::Sequence< sal_Int8 > SAL_CALL OFSStreamContainer::getImplementationId()
 // XStream
 uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -186,7 +186,7 @@ uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream()
 
 uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -203,7 +203,7 @@ uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream
 // XComponent
 void SAL_CALL OFSStreamContainer::dispose()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -223,44 +223,37 @@ void SAL_CALL OFSStreamContainer::dispose()
         m_bOutputClosed = true;
     }
 
-    if ( m_pListenersContainer )
-    {
-        lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
-        m_pListenersContainer->disposeAndClear( aSource );
-    }
-
+    lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
+    m_aListenersContainer.disposeAndClear( aGuard, aSource );
+    aGuard.lock();
     m_bDisposed = true;
 }
 
 void SAL_CALL OFSStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
 
-    if ( !m_pListenersContainer )
-        m_pListenersContainer.reset(new ::comphelper::OInterfaceContainerHelper2( m_aMutex ));
-
-    m_pListenersContainer->addInterface( xListener );
+    m_aListenersContainer.addInterface( xListener );
 }
 
 void SAL_CALL OFSStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
 
-    if ( m_pListenersContainer )
-        m_pListenersContainer->removeInterface( xListener );
+    m_aListenersContainer.removeInterface( xListener );
 }
 
 
 // XSeekable
 void SAL_CALL OFSStreamContainer::seek( sal_Int64 location )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -273,7 +266,7 @@ void SAL_CALL OFSStreamContainer::seek( sal_Int64 location )
 
 sal_Int64 SAL_CALL OFSStreamContainer::getPosition()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -286,7 +279,7 @@ sal_Int64 SAL_CALL OFSStreamContainer::getPosition()
 
 sal_Int64 SAL_CALL OFSStreamContainer::getLength()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -301,7 +294,7 @@ sal_Int64 SAL_CALL OFSStreamContainer::getLength()
 // XInputStream
 sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -314,7 +307,7 @@ sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aDa
 
 sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -327,7 +320,7 @@ sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >&
 
 void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -340,7 +333,7 @@ void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
 
 sal_Int32 SAL_CALL OFSStreamContainer::available()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -353,28 +346,31 @@ sal_Int32 SAL_CALL OFSStreamContainer::available()
 
 void SAL_CALL OFSStreamContainer::closeInput()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    {
+        std::scoped_lock aGuard( m_aMutex );
 
-    if ( m_bDisposed )
-        throw lang::DisposedException();
+        if ( m_bDisposed )
+            throw lang::DisposedException();
 
-    if ( !m_xStream.is() || !m_xInputStream.is() )
-        throw uno::RuntimeException();
+        if ( !m_xStream.is() || !m_xInputStream.is() )
+            throw uno::RuntimeException();
 
-    if ( m_xInputStream.is() )
-    {
-        m_xInputStream->closeInput();
-        m_bInputClosed = true;
+        if ( m_xInputStream.is() )
+        {
+            m_xInputStream->closeInput();
+            m_bInputClosed = true;
+        }
+        if ( !m_bOutputClosed )
+            return;
     }
 
-    if ( m_bOutputClosed )
-        dispose();
+    dispose();
 }
 
 // XOutputStream
 void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& aData )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -387,7 +383,7 @@ void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& a
 
 void SAL_CALL OFSStreamContainer::flush()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -400,29 +396,31 @@ void SAL_CALL OFSStreamContainer::flush()
 
 void SAL_CALL OFSStreamContainer::closeOutput()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    {
+        std::scoped_lock aGuard( m_aMutex );
 
-    if ( m_bDisposed )
-        throw lang::DisposedException();
+        if ( m_bDisposed )
+            throw lang::DisposedException();
 
-    if ( !m_xStream.is() || !m_xOutputStream.is() )
-        throw uno::RuntimeException();
+        if ( !m_xStream.is() || !m_xOutputStream.is() )
+            throw uno::RuntimeException();
 
-    if ( m_xOutputStream.is() )
-    {
-        m_xOutputStream->closeOutput();
-        m_bOutputClosed = true;
+        if ( m_xOutputStream.is() )
+        {
+            m_xOutputStream->closeOutput();
+            m_bOutputClosed = true;
+        }
+        if ( !m_bInputClosed )
+            return;
     }
-
-    if ( m_bInputClosed )
-        dispose();
+    dispose();
 }
 
 
 // XTruncate
 void SAL_CALL OFSStreamContainer::truncate()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
@@ -437,7 +435,7 @@ void SAL_CALL OFSStreamContainer::truncate()
 // XAsyncOutputMonitor
 void SAL_CALL OFSStreamContainer::waitForCompletion()
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
+    std::scoped_lock aGuard( m_aMutex );
 
     if ( m_bDisposed )
         throw lang::DisposedException();
diff --git a/svl/source/fsstor/ostreamcontainer.hxx b/svl/source/fsstor/ostreamcontainer.hxx
index fa461e955a7d..5b7e087a411c 100644
--- a/svl/source/fsstor/ostreamcontainer.hxx
+++ b/svl/source/fsstor/ostreamcontainer.hxx
@@ -29,8 +29,8 @@
 #include <com/sun/star/io/XStream.hpp>
 #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
 #include <cppuhelper/weak.hxx>
-#include <comphelper/interfacecontainer2.hxx>
-#include <osl/mutex.hxx>
+#include <comphelper/interfacecontainer4.hxx>
+#include <mutex>
 #include <memory>
 
 class OFSStreamContainer : public cppu::OWeakObject,
@@ -42,7 +42,7 @@ class OFSStreamContainer : public cppu::OWeakObject,
                      public css::io::XTruncate,
                      public css::io::XAsyncOutputMonitor
 {
-    ::osl::Mutex m_aMutex;
+    std::mutex m_aMutex;
 
     css::uno::Reference< css::io::XStream >               m_xStream;
     css::uno::Reference< css::io::XSeekable >             m_xSeekable;
@@ -55,7 +55,7 @@ class OFSStreamContainer : public cppu::OWeakObject,
     bool m_bInputClosed;
     bool m_bOutputClosed;
 
-    std::unique_ptr<::comphelper::OInterfaceContainerHelper2> m_pListenersContainer; // list of listeners
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aListenersContainer; // list of listeners
     css::uno::Sequence<css::uno::Type> m_aTypes;
 
 public:


More information about the Libreoffice-commits mailing list