chart2/source/controller/main/ChartController.cxx        |    7 -
 chart2/source/controller/main/ChartController_Window.cxx |   17 +-
 chart2/source/inc/LifeTime.hxx                           |   36 +++--
 chart2/source/model/main/ChartModel.cxx                  |   20 +--
 chart2/source/model/main/ChartModel_Persistence.cxx      |   43 ++----
 chart2/source/tools/LifeTime.cxx                         |   95 ++++++---------
 ucb/source/ucp/file/filtask.cxx                          |   74 ++++++-----
 ucb/source/ucp/file/filtask.hxx                          |    6 
 8 files changed, 145 insertions(+), 153 deletions(-)

New commits:
commit 6bd2da49262c94649bcba8c5760078c4a689acb2
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Feb 16 18:05:41 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Feb 16 20:11:51 2023 +0000

    osl::Mutex->std::mutex in LifeTimeManager
    
    Change-Id: I847b2718bbc9a80146e3685805faeca48203299b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147161
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index 6007499248c1..dbd7efb9d147 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -863,12 +863,12 @@ void SAL_CALL ChartController::dispose()
 void SAL_CALL ChartController::addEventListener(
     const uno::Reference<lang::XEventListener>& xListener )
 {
-    SolarMutexGuard aGuard;
     if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in 
suspend mode?
         return; //behave passive if already disposed or suspended
 
     //--add listener
-    m_aLifeTimeManager.m_aListenerContainer.addInterface( 
cppu::UnoType<lang::XEventListener>::get(), xListener );
+    std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aEventListeners.addInterface( aGuard2, xListener );
 }
 
 void SAL_CALL ChartController::removeEventListener(
@@ -879,7 +879,8 @@ void SAL_CALL ChartController::removeEventListener(
         return; //behave passive if already disposed or suspended
 
     //--remove listener
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface( 
cppu::UnoType<lang::XEventListener>::get(), xListener );
+    std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aEventListeners.removeInterface( aGuard2, xListener );
 }
 
 // util::XCloseListener
diff --git a/chart2/source/controller/main/ChartController_Window.cxx 
b/chart2/source/controller/main/ChartController_Window.cxx
index 5a16f1ca96bb..a3b108ee99de 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -1722,7 +1722,8 @@ void SAL_CALL 
ChartController::addSelectionChangeListener( const uno::Reference<
         return; //behave passive if already disposed or suspended
 
     //--add listener
-    m_aLifeTimeManager.m_aListenerContainer.addInterface( 
cppu::UnoType<view::XSelectionChangeListener>::get(), xListener );
+    std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aSelectionChangeListeners.addInterface( aGuard2, 
xListener );
 }
 
 void SAL_CALL ChartController::removeSelectionChangeListener( const 
uno::Reference<view::XSelectionChangeListener> & xListener )
@@ -1732,22 +1733,18 @@ void SAL_CALL 
ChartController::removeSelectionChangeListener( const uno::Referen
         return; //behave passive if already disposed or suspended
 
     //--remove listener
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface( 
cppu::UnoType<view::XSelectionChangeListener>::get(), xListener );
+    std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aSelectionChangeListeners.removeInterface( aGuard2, 
xListener );
 }
 
 void ChartController::impl_notifySelectionChangeListeners()
 {
-    ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aLifeTimeManager.m_aListenerContainer
-        .getContainer( cppu::UnoType<view::XSelectionChangeListener>::get() );
-    if( pIC )
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    if( m_aLifeTimeManager.m_aSelectionChangeListeners.getLength(aGuard) )
     {
         uno::Reference< view::XSelectionSupplier > xSelectionSupplier(this);
         lang::EventObject aEvent( xSelectionSupplier );
-        ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-        while( aIt.hasMoreElements() )
-        {
-            static_cast< view::XSelectionChangeListener* >( aIt.next() 
)->selectionChanged( aEvent );
-        }
+        m_aLifeTimeManager.m_aSelectionChangeListeners.notifyEach(aGuard, 
&view::XSelectionChangeListener::selectionChanged, aEvent);
     }
 }
 
diff --git a/chart2/source/inc/LifeTime.hxx b/chart2/source/inc/LifeTime.hxx
index 613d92314f96..fb9dd7a7f0b6 100644
--- a/chart2/source/inc/LifeTime.hxx
+++ b/chart2/source/inc/LifeTime.hxx
@@ -18,15 +18,19 @@
  */
 #pragma once
 
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <osl/conditn.hxx>
-#include <comphelper/multicontainer2.hxx>
+#include <comphelper/interfacecontainer4.hxx>
 #include "charttoolsdllapi.hxx"
 
+namespace com::sun::star::document { class XStorageChangeListener; }
 namespace com::sun::star::lang { class XComponent; }
+namespace com::sun::star::lang { class XEventListener; }
 namespace com::sun::star::util { class CloseVetoException; }
 namespace com::sun::star::util { class XCloseListener; }
 namespace com::sun::star::util { class XCloseable; }
+namespace com::sun::star::util { class XModifyListener; }
+namespace com::sun::star::view { class XSelectionChangeListener; }
 
 namespace apphelper
 {
@@ -34,8 +38,6 @@ namespace apphelper
 class OOO_DLLPUBLIC_CHARTTOOLS LifeTimeManager
 {
 friend class LifeTimeGuard;
-protected:
-    mutable ::osl::Mutex                    m_aAccessMutex;
 public:
     LifeTimeManager( css::lang::XComponent* pComponent );
     virtual ~LifeTimeManager();
@@ -44,25 +46,25 @@ public:
     /// @throws css::uno::RuntimeException
     bool    dispose();
 
-public:
-    ::comphelper::OMultiTypeInterfaceContainerHelper2      
m_aListenerContainer;
+    mutable std::mutex                    m_aAccessMutex;
+    ::comphelper::OInterfaceContainerHelper4<css::util::XCloseListener> 
m_aCloseListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> 
m_aModifyListeners;
+    
::comphelper::OInterfaceContainerHelper4<css::document::XStorageChangeListener> 
m_aStorageChangeListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_aEventListeners;
+    
::comphelper::OInterfaceContainerHelper4<css::view::XSelectionChangeListener> 
m_aSelectionChangeListeners;
 
 protected:
-    SAL_DLLPRIVATE virtual bool    impl_canStartApiCall();
-    SAL_DLLPRIVATE virtual void        impl_apiCallCountReachedNull(){}
+    SAL_DLLPRIVATE virtual bool impl_canStartApiCall();
+    SAL_DLLPRIVATE virtual void 
impl_apiCallCountReachedNull(std::unique_lock<std::mutex>& /*rGuard*/){}
 
     SAL_DLLPRIVATE void        impl_registerApiCall(bool bLongLastingCall);
-    SAL_DLLPRIVATE void        impl_unregisterApiCall(bool bLongLastingCall);
+    SAL_DLLPRIVATE void        
impl_unregisterApiCall(std::unique_lock<std::mutex>& rGuard, bool 
bLongLastingCall);
 
-protected:
     css::lang::XComponent*     m_pComponent;
-
     ::osl::Condition        m_aNoAccessCountCondition;
     sal_Int32               m_nAccessCount;
-
     bool volatile       m_bDisposed;
     bool volatile       m_bInDispose;
-
     ::osl::Condition        m_aNoLongLastingCallCountCondition;
     sal_Int32               m_nLongLastingCallCount;
 };
@@ -96,10 +98,10 @@ public:
 
 private:
     virtual bool    impl_canStartApiCall() override;
-    virtual void    impl_apiCallCountReachedNull() override;
+    virtual void impl_apiCallCountReachedNull(std::unique_lock<std::mutex>& 
rGuard) override;
 
     void        impl_setOwnership( bool bDeliverOwnership, bool bMyVeto );
-    void        impl_doClose();
+    void        impl_doClose(std::unique_lock<std::mutex>& rGuard);
 };
 
 /*
@@ -178,10 +180,10 @@ public:
     }
     bool startApiCall(bool bLongLastingCall=false);
     ~LifeTimeGuard();
-    void clear() { m_guard.clear(); }
+    void clear() { m_guard.unlock(); }
 
 private:
-    osl::ClearableMutexGuard m_guard;
+    std::unique_lock<std::mutex> m_guard;
     LifeTimeManager&    m_rManager;
     bool            m_bCallRegistered;
     bool            m_bLongLastingCallRegistered;
diff --git a/chart2/source/model/main/ChartModel.cxx 
b/chart2/source/model/main/ChartModel.cxx
index 0564f83703b8..56a143548ab3 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -250,16 +250,11 @@ uno::Reference< frame::XController > 
ChartModel::impl_getCurrentController()
 
 void ChartModel::impl_notifyCloseListeners()
 {
-    ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aLifeTimeManager.m_aListenerContainer
-        .getContainer( cppu::UnoType<util::XCloseListener>::get());
-    if( pIC )
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    if( m_aLifeTimeManager.m_aCloseListeners.getLength(aGuard) )
     {
         lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
-        ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-        while( aIt.hasMoreElements() )
-        {
-            static_cast< util::XCloseListener* >( aIt.next() )->notifyClosing( 
aEvent );
-        }
+        m_aLifeTimeManager.m_aCloseListeners.notifyEach(aGuard, 
&util::XCloseListener::notifyClosing, aEvent);
     }
 }
 
@@ -575,7 +570,8 @@ void SAL_CALL ChartModel::addEventListener( const 
uno::Reference< lang::XEventLi
     if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.addInterface( 
cppu::UnoType<lang::XEventListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aEventListeners.addInterface( aGuard, xListener );
 }
 
 void SAL_CALL ChartModel::removeEventListener( const uno::Reference< 
lang::XEventListener > & xListener )
@@ -583,7 +579,8 @@ void SAL_CALL ChartModel::removeEventListener( const 
uno::Reference< lang::XEven
     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface( 
cppu::UnoType<lang::XEventListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aEventListeners.removeInterface( aGuard, xListener );
 }
 
 // util::XCloseBroadcaster (base of XCloseable)
@@ -597,7 +594,8 @@ void SAL_CALL ChartModel::removeCloseListener( const 
uno::Reference< util::XClos
     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface( 
cppu::UnoType<util::XCloseListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aCloseListeners.removeInterface( aGuard, xListener );
 }
 
 // util::XCloseable
diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx 
b/chart2/source/model/main/ChartModel_Persistence.cxx
index 3572f1fa4288..986c5640c3d5 100644
--- a/chart2/source/model/main/ChartModel_Persistence.cxx
+++ b/chart2/source/model/main/ChartModel_Persistence.cxx
@@ -638,16 +638,11 @@ void ChartModel::impl_notifyModifiedListeners()
     //always notify the view first!
     ChartViewHelper::setViewToDirtyState( this );
 
-    ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aLifeTimeManager.m_aListenerContainer
-        .getContainer( cppu::UnoType<util::XModifyListener>::get());
-    if( pIC )
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    if( m_aLifeTimeManager.m_aModifyListeners.getLength(aGuard) )
     {
         lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
-        ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-        while( aIt.hasMoreElements() )
-        {
-            static_cast< util::XModifyListener* >( aIt.next() )->modified( 
aEvent );
-        }
+        m_aLifeTimeManager.m_aModifyListeners.notifyEach(aGuard, 
&util::XModifyListener::modified, aEvent);
     }
 }
 
@@ -692,8 +687,8 @@ void SAL_CALL ChartModel::addModifyListener(
     if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.addInterface(
-        cppu::UnoType<util::XModifyListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aModifyListeners.addInterface( aGuard, xListener );
 }
 
 void SAL_CALL ChartModel::removeModifyListener(
@@ -702,8 +697,8 @@ void SAL_CALL ChartModel::removeModifyListener(
     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface(
-        cppu::UnoType<util::XModifyListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aModifyListeners.removeInterface( aGuard, xListener );
 }
 
 // util::XModifyListener
@@ -772,16 +767,14 @@ Reference< embed::XStorage > SAL_CALL 
ChartModel::getDocumentStorage()
 
 void ChartModel::impl_notifyStorageChangeListeners()
 {
-    ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aLifeTimeManager.m_aListenerContainer
-          .getContainer( 
cppu::UnoType<document::XStorageChangeListener>::get());
-    if( pIC )
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    if( m_aLifeTimeManager.m_aStorageChangeListeners.getLength(aGuard) )
     {
-        ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-        while( aIt.hasMoreElements() )
-        {
-            static_cast< document::XStorageChangeListener* >( aIt.next() )
-                ->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( 
this ), m_xStorage );
-        }
+        m_aLifeTimeManager.m_aStorageChangeListeners.forEach(aGuard,
+            [this](const uno::Reference<document::XStorageChangeListener>& l)
+            {
+                l->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( 
this ), m_xStorage );
+            });
     }
 }
 
@@ -790,8 +783,8 @@ void SAL_CALL ChartModel::addStorageChangeListener( const 
Reference< document::X
     if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.addInterface(
-        cppu::UnoType<document::XStorageChangeListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aStorageChangeListeners.addInterface( aGuard, 
xListener );
 }
 
 void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< 
document::XStorageChangeListener >& xListener )
@@ -799,8 +792,8 @@ void SAL_CALL ChartModel::removeStorageChangeListener( 
const Reference< document
     if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
         return; //behave passive if already disposed or closed
 
-    m_aLifeTimeManager.m_aListenerContainer.removeInterface(
-        cppu::UnoType<document::XStorageChangeListener>::get(), xListener );
+    std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
+    m_aLifeTimeManager.m_aStorageChangeListeners.removeInterface(aGuard, 
xListener );
 }
 
 } //  namespace chart
diff --git a/chart2/source/tools/LifeTime.cxx b/chart2/source/tools/LifeTime.cxx
index f3711736026e..45550b93efdd 100644
--- a/chart2/source/tools/LifeTime.cxx
+++ b/chart2/source/tools/LifeTime.cxx
@@ -20,10 +20,13 @@
 #include <LifeTime.hxx>
 #include <osl/diagnose.h>
 
+#include <com/sun/star/document/XStorageChangeListener.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/util/CloseVetoException.hpp>
 #include <com/sun/star/util/XCloseListener.hpp>
 #include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/XModifyListener.hpp>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
 #include <comphelper/diagnose_ex.hxx>
 #include <sal/log.hxx>
 
@@ -33,8 +36,7 @@ namespace apphelper
 {
 
 LifeTimeManager::LifeTimeManager( lang::XComponent* pComponent )
-    : m_aListenerContainer( m_aAccessMutex )
-    , m_pComponent(pComponent)
+    : m_pComponent(pComponent)
 {
     m_bDisposed = false;
     m_bInDispose = false;
@@ -85,7 +87,7 @@ void LifeTimeManager::impl_registerApiCall(bool 
bLongLastingCall)
         m_aNoLongLastingCallCountCondition.reset();
 }
 
-void LifeTimeManager::impl_unregisterApiCall(bool bLongLastingCall)
+void LifeTimeManager::impl_unregisterApiCall(std::unique_lock<std::mutex>& 
rGuard, bool bLongLastingCall)
 {
     //Mutex needs to be acquired exactly once
     //mutex may be released inbetween in special case of 
impl_apiCallCountReachedNull()
@@ -101,7 +103,7 @@ void LifeTimeManager::impl_unregisterApiCall(bool 
bLongLastingCall)
     if( m_nAccessCount== 0)
     {
         m_aNoAccessCountCondition.set();
-        impl_apiCallCountReachedNull();
+        impl_apiCallCountReachedNull(rGuard);
 
     }
 }
@@ -110,7 +112,7 @@ bool LifeTimeManager::dispose()
 {
     //hold no mutex
     {
-        osl::MutexGuard aGuard( m_aAccessMutex );
+        std::unique_lock aGuard( m_aAccessMutex );
 
         if( m_bDisposed || m_bInDispose )
         {
@@ -122,23 +124,19 @@ bool LifeTimeManager::dispose()
         //adding any listener is not allowed anymore
         //new calls will not be accepted
         //still running calls have the freedom to finish their work without 
crash
-    }
-    //no mutex is acquired
 
-    //--do the disposing of listeners after calling this method
-    {
         uno::Reference< lang::XComponent > xComponent(m_pComponent);
         if(xComponent.is())
         {
             // notify XCLoseListeners
             lang::EventObject aEvent( xComponent );
-            m_aListenerContainer.disposeAndClear( aEvent );
+            m_aCloseListeners.disposeAndClear( aGuard, aEvent );
+            m_aModifyListeners.disposeAndClear( aGuard, aEvent );
+            m_aStorageChangeListeners.disposeAndClear( aGuard, aEvent );
+            m_aEventListeners.disposeAndClear( aGuard, aEvent );
+            m_aSelectionChangeListeners.disposeAndClear( aGuard, aEvent );
         }
-    }
 
-    //no mutex is acquired
-    {
-        osl::MutexGuard aGuard( m_aAccessMutex );
         OSL_ENSURE( !m_bDisposed, "dispose was called already" );
         m_bDisposed = true;
     }
@@ -189,7 +187,7 @@ bool CloseableLifeTimeManager::g_close_startTryClose(bool 
bDeliverOwnership)
 {
     //no mutex is allowed to be acquired
     {
-        osl::MutexGuard aGuard( m_aAccessMutex );
+        std::unique_lock aGuard( m_aAccessMutex );
         if( impl_isDisposedOrClosed(false) )
             return false;
 
@@ -217,18 +215,16 @@ bool CloseableLifeTimeManager::g_close_startTryClose(bool 
bDeliverOwnership)
         uno::Reference< util::XCloseable > xCloseable(m_pCloseable);
         if(xCloseable.is())
         {
+            std::unique_lock aGuard( m_aAccessMutex );
             //--call queryClosing on all registered close listeners
-            ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aListenerContainer.getContainer(
-                        cppu::UnoType<util::XCloseListener>::get());
-            if( pIC )
+            if( m_aCloseListeners.getLength(aGuard) )
             {
                 lang::EventObject aEvent( xCloseable );
-                ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-                while( aIt.hasMoreElements() )
-                {
-                    static_cast< util::XCloseListener* >( aIt.next() )
-                        ->queryClosing( aEvent, bDeliverOwnership );
-                }
+                m_aCloseListeners.forEach(aGuard,
+                    [&aEvent, bDeliverOwnership](const 
uno::Reference<util::XCloseListener>& l)
+                    {
+                        l->queryClosing(aEvent, bDeliverOwnership);
+                    });
             }
         }
     }
@@ -244,7 +240,7 @@ bool CloseableLifeTimeManager::g_close_startTryClose(bool 
bDeliverOwnership)
 void CloseableLifeTimeManager::g_close_endTryClose(bool bDeliverOwnership )
 {
     //this method is called, if the try to close was not successful
-    osl::MutexGuard aGuard( m_aAccessMutex );
+    std::unique_lock aGuard( m_aAccessMutex );
     impl_setOwnership( bDeliverOwnership, false );
 
     m_bInTryClose = false;
@@ -252,7 +248,7 @@ void CloseableLifeTimeManager::g_close_endTryClose(bool 
bDeliverOwnership )
 
     //Mutex needs to be acquired exactly once
     //mutex may be released inbetween in special case of 
impl_apiCallCountReachedNull()
-    impl_unregisterApiCall(false);
+    impl_unregisterApiCall(aGuard, false);
 }
 
 void CloseableLifeTimeManager::g_close_isNeedToCancelLongLastingCalls( bool 
bDeliverOwnership, util::CloseVetoException const & ex )
@@ -262,7 +258,7 @@ void 
CloseableLifeTimeManager::g_close_isNeedToCancelLongLastingCalls( bool bDel
     //it returns true, if some longlasting calls are running, which might be 
cancelled
     //it throws the given exception, if long calls are running but not 
cancelable
 
-    osl::MutexGuard aGuard( m_aAccessMutex );
+    std::unique_lock aGuard( m_aAccessMutex );
     //this count cannot grow after try of close has started, because we wait 
in all those methods for end of try closing
     if( !m_nLongLastingCallCount )
         return;
@@ -274,7 +270,7 @@ void 
CloseableLifeTimeManager::g_close_isNeedToCancelLongLastingCalls( bool bDel
 
     //Mutex needs to be acquired exactly once
     //mutex may be released inbetween in special case of 
impl_apiCallCountReachedNull()
-    impl_unregisterApiCall(false);
+    impl_unregisterApiCall(aGuard, false);
 
     throw ex;
 }
@@ -282,15 +278,15 @@ void 
CloseableLifeTimeManager::g_close_isNeedToCancelLongLastingCalls( bool bDel
 void CloseableLifeTimeManager::g_close_endTryClose_doClose()
 {
     //this method is called, if the try to close was successful
-    osl::MutexGuard aGuard( m_aAccessMutex );
+    std::unique_lock aGuard( m_aAccessMutex );
 
     m_bInTryClose       = false;
     m_aEndTryClosingCondition.set();
 
     //Mutex needs to be acquired exactly once
     //mutex may be released inbetween in special case of 
impl_apiCallCountReachedNull()
-    impl_unregisterApiCall(false);
-    impl_doClose();
+    impl_unregisterApiCall(aGuard, false);
+    impl_doClose(aGuard);
 }
 
 void CloseableLifeTimeManager::impl_setOwnership( bool bDeliverOwnership, bool 
bMyVeto )
@@ -298,15 +294,15 @@ void CloseableLifeTimeManager::impl_setOwnership( bool 
bDeliverOwnership, bool b
     m_bOwnership            = bDeliverOwnership && bMyVeto;
 }
 
-void CloseableLifeTimeManager::impl_apiCallCountReachedNull()
+void 
CloseableLifeTimeManager::impl_apiCallCountReachedNull(std::unique_lock<std::mutex>&
 rGuard)
 {
     //Mutex needs to be acquired exactly once
     //mutex will be released inbetween in impl_doClose()
     if( m_pCloseable && m_bOwnership )
-        impl_doClose();
+        impl_doClose(rGuard);
 }
 
-void CloseableLifeTimeManager::impl_doClose()
+void CloseableLifeTimeManager::impl_doClose(std::unique_lock<std::mutex>& 
rGuard)
 {
     //Mutex needs to be acquired exactly once before calling impl_doClose()
 
@@ -317,26 +313,17 @@ void CloseableLifeTimeManager::impl_doClose()
 
     m_bClosed = true;
 
-    NegativeGuard< osl::Mutex > aNegativeGuard( m_aAccessMutex );
-    //mutex is not acquired, mutex will be reacquired at the end of this 
method automatically
-
     uno::Reference< util::XCloseable > xCloseable;
+    xCloseable.set(m_pCloseable);
     try
     {
-        xCloseable.set(m_pCloseable);
         if(xCloseable.is())
         {
             //--call notifyClosing on all registered close listeners
-            ::comphelper::OInterfaceContainerHelper2* pIC = 
m_aListenerContainer.getContainer(
-                        cppu::UnoType<util::XCloseListener>::get());
-            if( pIC )
+            if( m_aCloseListeners.getLength(rGuard) )
             {
                 lang::EventObject aEvent( xCloseable );
-                ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC );
-                while( aIt.hasMoreElements() )
-                {
-                    static_cast< util::XCloseListener* >( aIt.next() 
)->notifyClosing( aEvent );
-                }
+                m_aCloseListeners.notifyEach(rGuard, 
&util::XCloseListener::notifyClosing, aEvent);
             }
         }
     }
@@ -345,6 +332,7 @@ void CloseableLifeTimeManager::impl_doClose()
         DBG_UNHANDLED_EXCEPTION("chart2");
     }
 
+    rGuard.unlock();
     if(xCloseable.is())
     {
         uno::Reference< lang::XComponent > xComponent( xCloseable, 
uno::UNO_QUERY );
@@ -354,18 +342,18 @@ void CloseableLifeTimeManager::impl_doClose()
             xComponent->dispose();
         }
     }
-    //mutex will be reacquired in destructor of aNegativeGuard
+    rGuard.lock();
 }
 
 void CloseableLifeTimeManager::g_addCloseListener( const uno::Reference< 
util::XCloseListener > & xListener )
 {
-    osl::MutexGuard aGuard( m_aAccessMutex );
+    std::unique_lock aGuard( m_aAccessMutex );
     //Mutex needs to be acquired exactly once; will be released inbetween
     if( !impl_canStartApiCall() )
         return;
     //mutex is acquired
 
-    m_aListenerContainer.addInterface( 
cppu::UnoType<util::XCloseListener>::get(),xListener );
+    m_aCloseListeners.addInterface( aGuard, xListener );
     m_bOwnership = false;
 }
 
@@ -386,9 +374,9 @@ bool CloseableLifeTimeManager::impl_canStartApiCall()
         //we need to wait for his end because the result of the preceding call
         //is relevant for our behaviour here
 
-        m_aAccessMutex.release();
+        m_aAccessMutex.unlock();
         m_aEndTryClosingCondition.wait(); //@todo??? this may block??? try 
closing
-        m_aAccessMutex.acquire();
+        m_aAccessMutex.lock();
         if( m_bDisposed || m_bInDispose || m_bClosed )
             return false; //return if closed already
     }
@@ -421,12 +409,13 @@ LifeTimeGuard::~LifeTimeGuard()
     try
     {
         //do acquire the mutex if it was cleared before
-        osl::MutexGuard g(m_rManager.m_aAccessMutex);
+        if (!m_guard.owns_lock())
+            m_guard.lock();
         if(m_bCallRegistered)
         {
             //Mutex needs to be acquired exactly once
             //mutex may be released inbetween in special case of 
impl_apiCallCountReachedNull()
-            m_rManager.impl_unregisterApiCall(m_bLongLastingCallRegistered);
+            m_rManager.impl_unregisterApiCall(m_guard, 
m_bLongLastingCallRegistered);
         }
     }
     catch( uno::Exception& ex )
commit 46d2d1b9ffe53f5a7a82b62179ee4d725b13f8d0
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Feb 16 14:57:08 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Feb 16 20:11:38 2023 +0000

    osl::Mutex->std::mutex in TaskManager
    
    Change-Id: I1ab5183cff5eaed9e3c0821115c7f89850d3b482
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147160
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/ucb/source/ucp/file/filtask.cxx b/ucb/source/ucp/file/filtask.cxx
index 7c87f5652be7..795788ca4125 100644
--- a/ucb/source/ucp/file/filtask.cxx
+++ b/ucb/source/ucp/file/filtask.cxx
@@ -368,7 +368,7 @@ TaskManager::startTask(
     sal_Int32 CommandId,
     const uno::Reference< XCommandEnvironment >& xCommandEnv )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     if( it != m_aTaskMap.end() )
     {
@@ -383,7 +383,7 @@ TaskManager::endTask( sal_Int32 CommandId,
                       const OUString& aUncPath,
                       BaseContent* pContent)
 {
-    osl::ClearableMutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     if( it == m_aTaskMap.end() )
         return;
@@ -397,7 +397,7 @@ TaskManager::endTask( sal_Int32 CommandId,
 
     m_aTaskMap.erase( it );
 
-    aGuard.clear();
+    aGuard.unlock();
 
     if( ErrorCode != TASKHANDLER_NO_ERROR )
         throw_handler(
@@ -412,7 +412,7 @@ TaskManager::endTask( sal_Int32 CommandId,
 
 void TaskManager::clearError( sal_Int32 CommandId )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     if( it != m_aTaskMap.end() )
         it->second.clearError();
@@ -423,7 +423,7 @@ void TaskManager::retrieveError( sal_Int32 CommandId,
                                           sal_Int32 &ErrorCode,
                                           sal_Int32 &minorCode)
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     if( it != m_aTaskMap.end() )
     {
@@ -437,7 +437,7 @@ void TaskManager::installError( sal_Int32 CommandId,
                                          sal_Int32 ErrorCode,
                                          sal_Int32 MinorCode )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     if( it != m_aTaskMap.end() )
         it->second.installError( ErrorCode,MinorCode );
@@ -447,7 +447,7 @@ void TaskManager::installError( sal_Int32 CommandId,
 sal_Int32
 TaskManager::getCommandId()
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     return ++m_nCommandId;
 }
 
@@ -456,7 +456,7 @@ void TaskManager::handleTask(
     sal_Int32 CommandId,
     const uno::Reference< task::XInteractionRequest >& request )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     TaskMap::iterator it = m_aTaskMap.find( CommandId );
     uno::Reference< task::XInteractionHandler > xInt;
     if( it != m_aTaskMap.end() )
@@ -482,7 +482,7 @@ void TaskManager::handleTask(
 void
 TaskManager::registerNotifier( const OUString& aUnqPath, Notifier* pNotifier )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     ContentMap::iterator it =
         m_aContent.emplace( aUnqPath, UnqPathData() ).first;
@@ -501,7 +501,7 @@ TaskManager::registerNotifier( const OUString& aUnqPath, 
Notifier* pNotifier )
 void
 TaskManager::deregisterNotifier( const OUString& aUnqPath,Notifier* pNotifier )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     ContentMap::iterator it = m_aContent.find( aUnqPath );
     if( it == m_aContent.end() )
@@ -544,7 +544,7 @@ TaskManager::associate( const OUString& aUnqPath,
         throw beans::PropertyExistException( THROW_WHERE );
 
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
 
         ContentMap::iterator it = m_aContent.emplace( aUnqPath,UnqPathData() 
).first;
 
@@ -574,11 +574,11 @@ TaskManager::deassociate( const OUString& aUnqPath,
     if( it1 != m_aDefaultProperties.end() )
         throw beans::NotRemoveableException( THROW_WHERE );
 
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     ContentMap::iterator it = m_aContent.emplace( aUnqPath,UnqPathData() 
).first;
 
-    load( it,false );
+    load( it, false );
 
     PropertySet& properties = it->second.properties;
 
@@ -604,6 +604,7 @@ TaskManager::deassociate( const OUString& aUnqPath,
                 m_xFileRegistry->removePropertySet( aUnqPath );
         }
     }
+    aGuard.unlock();
     notifyPropertyRemoved( getPropertySetListeners( aUnqPath ), PropertyName );
 }
 
@@ -817,7 +818,7 @@ TaskManager::info_c()
 uno::Reference< beans::XPropertySetInfo >
 TaskManager::info_p( const OUString& aUnqPath )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     return new XPropertySetInfo_impl( this,aUnqPath );
 }
 
@@ -835,7 +836,7 @@ uno::Sequence< uno::Any >
 TaskManager::setv( const OUString& aUnqPath,
              const uno::Sequence< beans::PropertyValue >& values )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     sal_Int32 propChanged = 0;
     uno::Sequence< uno::Any > ret( values.getLength() );
@@ -880,7 +881,7 @@ TaskManager::setv( const OUString& aUnqPath,
         {
             // Also put logical properties into storage
             if( !it->second.xS.is() )
-                load( it,true );
+                load( it, true );
 
             if( ( values[i].Name == ContentType ) &&
                 it1->getState() == beans::PropertyState_DEFAULT_VALUE )
@@ -1045,10 +1046,11 @@ TaskManager::setv( const OUString& aUnqPath,
         }
     }   // end for
 
+    aGuard.unlock();
     if( propChanged )
     {
         seqChanged.realloc( propChanged );
-        notifyPropertyChanges( getPropertyChangeNotifier( aUnqPath 
),seqChanged );
+        notifyPropertyChanges( getPropertyChangeNotifier( aUnqPath ), 
seqChanged );
     }
 
     return ret;
@@ -1090,10 +1092,10 @@ TaskManager::getv( sal_Int32 CommandId,
                      nError2);
 
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
 
         TaskManager::ContentMap::iterator it = m_aContent.find( aUnqPath );
-        commit( it,aFileStatus );
+        commit( aGuard, it, aFileStatus );
 
         PropertySet& propset = it->second.properties;
 
@@ -1922,12 +1924,16 @@ TaskManager::write( sal_Int32 CommandId,
 
 void TaskManager::insertDefaultProperties( const OUString& aUnqPath )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard(m_aMutex);
+    insertDefaultProperties(aGuard, aUnqPath);
+}
 
+void TaskManager::insertDefaultProperties( std::unique_lock<std::mutex>& 
/*rGuard*/, const OUString& aUnqPath )
+{
     ContentMap::iterator it =
         m_aContent.emplace( aUnqPath,UnqPathData() ).first;
 
-    load( it,false );
+    load( it, false );
 
     MyProperty ContentTProperty( ContentType );
 
@@ -2241,7 +2247,8 @@ TaskManager::load( const ContentMap::iterator& it, bool 
create )
 
 
 void
-TaskManager::commit( const TaskManager::ContentMap::iterator& it,
+TaskManager::commit( std::unique_lock<std::mutex>& rGuard,
+               const TaskManager::ContentMap::iterator& it,
                const osl::FileStatus& aFileStatus )
 {
     TaskManager::PropertySet::const_iterator it1;
@@ -2249,7 +2256,7 @@ TaskManager::commit( const 
TaskManager::ContentMap::iterator& it,
     if( it->second.properties.empty() )
     {
         OUString aPath = it->first;
-        insertDefaultProperties( aPath );
+        insertDefaultProperties( rGuard, aPath );
     }
 
     PropertySet& properties = it->second.properties;
@@ -2511,12 +2518,13 @@ TaskManager::getv(
     else
         aIsRegular = aFileStatus.getFileType() == osl::FileStatus::Regular;
 
-    insertDefaultProperties( aUnqPath );
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
+
+        insertDefaultProperties( aGuard, aUnqPath );
 
         TaskManager::ContentMap::iterator it = m_aContent.find( aUnqPath );
-        commit( it,aFileStatus );
+        commit( aGuard, it, aFileStatus );
 
         PropertySet& propset = it->second.properties;
 
@@ -2543,7 +2551,7 @@ TaskManager::getContentEventListeners( const OUString& 
aName )
 {
     std::vector< ContentEventNotifier > listeners;
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         TaskManager::ContentMap::iterator it = m_aContent.find( aName );
         if( it != m_aContent.end() && !it->second.notifier.empty() )
         {
@@ -2565,7 +2573,7 @@ TaskManager::getContentDeletedEventListeners( const 
OUString& aName )
 {
     std::vector< ContentEventNotifier > listeners;
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         TaskManager::ContentMap::iterator it = m_aContent.find( aName );
         if( it != m_aContent.end() && !it->second.notifier.empty() )
         {
@@ -2614,7 +2622,7 @@ TaskManager::getPropertySetListeners( const OUString& 
aName )
 {
     std::vector< PropertySetInfoChangeNotifier > listeners;
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         TaskManager::ContentMap::iterator it = m_aContent.find( aName );
         if( it != m_aContent.end() && !it->second.notifier.empty() )
         {
@@ -2664,7 +2672,7 @@ TaskManager::getContentExchangedEventListeners( const 
OUString& aOldPrefix,
     std::vector< OUString > oldChildList;
 
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
 
         if( ! withChildren )
         {
@@ -2676,7 +2684,7 @@ TaskManager::getContentExchangedEventListeners( const 
OUString& aOldPrefix,
         {
             for (auto const& content : m_aContent)
             {
-                if( isChild( aOldPrefix,content.first ) )
+                if( isChild( aOldPrefix, content.first ) )
                 {
                     oldChildList.push_back( content.first );
                 }
@@ -2749,7 +2757,7 @@ TaskManager::getPropertyChangeNotifier( const OUString& 
aName )
 {
     std::vector< PropertyChangeNotifier > listeners;
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         TaskManager::ContentMap::iterator it = m_aContent.find( aName );
         if( it != m_aContent.end() && !it->second.notifier.empty() )
         {
@@ -2785,7 +2793,7 @@ TaskManager::erasePersistentSetWithoutChildren( const 
OUString& aUnqPath )
 {
     {
         // Release possible references
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         ContentMap::iterator it = m_aContent.find( aUnqPath );
         if( it != m_aContent.end() )
         {
diff --git a/ucb/source/ucp/file/filtask.hxx b/ucb/source/ucp/file/filtask.hxx
index 80879a22e597..c2623c60be05 100644
--- a/ucb/source/ucp/file/filtask.hxx
+++ b/ucb/source/ucp/file/filtask.hxx
@@ -46,6 +46,7 @@
 #include <com/sun/star/task/XInteractionRequest.hpp>
 #include "filerror.hxx"
 #include "filnot.hxx"
+#include <mutex>
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
@@ -148,7 +149,7 @@ namespace fileaccess
         typedef std::unordered_map< sal_Int32,TaskHandling > TaskMap;
     private:
 
-        osl::Mutex                                                         
m_aMutex;
+        std::mutex                                                          
m_aMutex;
         sal_Int32                                                           
m_nCommandId;
         TaskMap                                                             
m_aTaskMap;
 
@@ -479,6 +480,8 @@ namespace fileaccess
 
     private:
 
+        void insertDefaultProperties( std::unique_lock<std::mutex>& rGuard, 
const OUString& aUnqPath );
+
         
/********************************************************************************/
         /*                              get eventListeners                     
         */
         
/********************************************************************************/
@@ -578,6 +581,7 @@ namespace fileaccess
 
         void
         commit(
+            std::unique_lock<std::mutex>& rGuard,
             const TaskManager::ContentMap::iterator& it,
             const osl::FileStatus& aFileStatus );
 

Reply via email to