ucb/source/ucp/file/bc.cxx     |  160 ++++++++++++++---------------------------
 ucb/source/ucp/file/bc.hxx     |   14 +--
 ucb/source/ucp/file/filnot.cxx |    2 
 3 files changed, 63 insertions(+), 113 deletions(-)

New commits:
commit 3816184ee779f32d2210c8fcc9f7dd2c77b6f736
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun May 8 21:24:32 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 10 19:39:36 2022 +0200

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

diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx
index e4ed0f180333..03590d3e0173 100644
--- a/ucb/source/ucp/file/bc.cxx
+++ b/ucb/source/ucp/file/bc.cxx
@@ -54,63 +54,42 @@ using namespace com::sun::star::ucb;
 
 class fileaccess::PropertyListeners
 {
-    typedef 
comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener> 
ContainerHelper;
-    osl::Mutex& rMutex;
+    typedef 
comphelper::OInterfaceContainerHelper4<beans::XPropertiesChangeListener> 
ContainerHelper;
     std::unordered_map<OUString, ContainerHelper> m_aMap;
+
 public:
-    explicit PropertyListeners( ::osl::Mutex& aMutex )
-        : rMutex( aMutex )
-    {
-    }
-    void disposeAndClear(const lang::EventObject& rEvt)
+    void disposeAndClear(std::unique_lock<std::mutex>& rGuard, const 
lang::EventObject& rEvt)
     {
         // create a copy, because do not fire event in a guarded section
-        std::unordered_map<OUString, ContainerHelper> tempMap;
-        {
-            ::osl::MutexGuard aGuard(rMutex);
-            tempMap = std::move(m_aMap);
-        }
+        std::unordered_map<OUString, ContainerHelper> tempMap = 
std::move(m_aMap);
         for (auto& rPair : tempMap)
-            rPair.second.disposeAndClear(rEvt);
+            rPair.second.disposeAndClear(rGuard, rEvt);
     }
-    void addInterface(const OUString& rKey, const 
uno::Reference<beans::XPropertiesChangeListener>& rListener)
+    void addInterface(std::unique_lock<std::mutex>& rGuard, const OUString& 
rKey, const uno::Reference<beans::XPropertiesChangeListener>& rListener)
     {
-        ::osl::MutexGuard aGuard(rMutex);
-        auto iter = m_aMap.find(rKey);
-        if (iter == m_aMap.end())
-        {
-            auto ret = m_aMap.emplace(rKey, rMutex);
-            ret.first->second.addInterface(rListener);
-        }
-        else
-            iter->second.addInterface(rListener);
+        m_aMap[rKey].addInterface(rGuard, rListener);
     }
-    void removeInterface(const OUString& rKey, const 
uno::Reference<beans::XPropertiesChangeListener>& rListener)
+    void removeInterface(std::unique_lock<std::mutex>& rGuard, const OUString& 
rKey, const uno::Reference<beans::XPropertiesChangeListener>& rListener)
     {
-        ::osl::MutexGuard aGuard(rMutex);
-
         // search container with id rKey
         auto iter = m_aMap.find(rKey);
         // container found?
         if (iter != m_aMap.end())
-            iter->second.removeInterface(rListener);
+            iter->second.removeInterface(rGuard, rListener);
     }
-    std::vector< OUString > getContainedTypes() const
+    std::vector< OUString > getContainedTypes(std::unique_lock<std::mutex>& 
rGuard) const
     {
-        ::osl::MutexGuard aGuard(rMutex);
         std::vector<OUString> aInterfaceTypes;
         aInterfaceTypes.reserve(m_aMap.size());
         for (const auto& rPair : m_aMap)
             // are interfaces added to this container?
-            if (rPair.second.getLength())
+            if (rPair.second.getLength(rGuard))
                 // yes, put the type in the array
                 aInterfaceTypes.push_back(rPair.first);
         return aInterfaceTypes;
     }
-    comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener>* 
getContainer(const OUString& rKey)
+    comphelper::OInterfaceContainerHelper4<beans::XPropertiesChangeListener>* 
getContainer(std::unique_lock<std::mutex>& , const OUString& rKey)
     {
-        ::osl::MutexGuard aGuard(rMutex);
-
         auto iter = m_aMap.find(rKey);
         if (iter != m_aMap.end())
             return &iter->second;
@@ -174,23 +153,18 @@ BaseContent::~BaseContent( )
 void SAL_CALL
 BaseContent::addEventListener( const Reference< lang::XEventListener >& 
Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
-    if ( ! m_pDisposeEventListeners )
-        m_pDisposeEventListeners.reset(
-            new comphelper::OInterfaceContainerHelper3<lang::XEventListener>( 
m_aEventListenerMutex ) );
-
-    m_pDisposeEventListeners->addInterface( Listener );
+    m_aDisposeEventListeners.addInterface( aGuard, Listener );
 }
 
 
 void SAL_CALL
 BaseContent::removeEventListener( const Reference< lang::XEventListener >& 
Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
-    if ( m_pDisposeEventListeners )
-        m_pDisposeEventListeners->removeInterface( Listener );
+    m_aDisposeEventListeners.removeInterface( aGuard, Listener );
 }
 
 
@@ -198,32 +172,19 @@ void SAL_CALL
 BaseContent::dispose()
 {
     lang::EventObject aEvt;
-    
std::unique_ptr<comphelper::OInterfaceContainerHelper3<lang::XEventListener>> 
pDisposeEventListeners;
-    
std::unique_ptr<comphelper::OInterfaceContainerHelper3<XContentEventListener>> 
pContentEventListeners;
-    
std::unique_ptr<comphelper::OInterfaceContainerHelper3<beans::XPropertySetInfoChangeListener>>
 pPropertySetInfoChangeListeners;
-    std::unique_ptr<PropertyListeners> pPropertyListener;
-
-    {
-        osl::MutexGuard aGuard( m_aMutex );
-        aEvt.Source = static_cast< XContent* >( this );
+    aEvt.Source = static_cast< XContent* >( this );
 
-        pDisposeEventListeners = std::move(m_pDisposeEventListeners);
-        pContentEventListeners = std::move(m_pContentEventListeners);
-        pPropertySetInfoChangeListeners = 
std::move(m_pPropertySetInfoChangeListeners);
-        pPropertyListener = std::move(m_pPropertyListener);
-    }
+    std::unique_lock aGuard( m_aMutex );
 
-    if ( pDisposeEventListeners && pDisposeEventListeners->getLength() )
-        pDisposeEventListeners->disposeAndClear( aEvt );
+    std::unique_ptr<PropertyListeners> pPropertyListener = 
std::move(m_pPropertyListener);
 
-    if ( pContentEventListeners && pContentEventListeners->getLength() )
-        pContentEventListeners->disposeAndClear( aEvt );
+    m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt );
+    m_aContentEventListeners.disposeAndClear( aGuard, aEvt );
 
     if( pPropertyListener )
-        pPropertyListener->disposeAndClear( aEvt );
+        pPropertyListener->disposeAndClear( aGuard, aEvt );
 
-    if( pPropertySetInfoChangeListeners )
-        pPropertySetInfoChangeListeners->disposeAndClear( aEvt );
+    m_aPropertySetInfoChangeListeners.disposeAndClear( aGuard, aEvt );
 }
 
 //  XServiceInfo
@@ -380,20 +341,20 @@ BaseContent::addPropertiesChangeListener(
     if( ! Listener.is() )
         return;
 
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     if( ! m_pPropertyListener )
-        m_pPropertyListener.reset( new PropertyListeners( 
m_aEventListenerMutex ) );
+        m_pPropertyListener.reset( new PropertyListeners );
 
 
     if( !PropertyNames.hasElements() )
-        m_pPropertyListener->addInterface( OUString(),Listener );
+        m_pPropertyListener->addInterface( aGuard, OUString(),Listener );
     else
     {
         Reference< beans::XPropertySetInfo > xProp = m_pMyShell->info_p( 
m_aUncPath );
         for( const auto& rName : PropertyNames )
             if( xProp->hasPropertyByName( rName ) )
-                m_pPropertyListener->addInterface( rName,Listener );
+                m_pPropertyListener->addInterface( aGuard, rName,Listener );
     }
 }
 
@@ -405,15 +366,15 @@ BaseContent::removePropertiesChangeListener( const 
Sequence< OUString >& Propert
     if( ! Listener.is() )
         return;
 
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     if( ! m_pPropertyListener )
         return;
 
     for( const auto& rName : PropertyNames )
-        m_pPropertyListener->removeInterface( rName,Listener );
+        m_pPropertyListener->removeInterface( aGuard, rName,Listener );
 
-    m_pPropertyListener->removeInterface( OUString(), Listener );
+    m_pPropertyListener->removeInterface( aGuard, OUString(), Listener );
 }
 
 
@@ -474,14 +435,9 @@ void SAL_CALL
 BaseContent::addContentEventListener(
     const Reference< XContentEventListener >& Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
-
-    if ( ! m_pContentEventListeners )
-        m_pContentEventListeners.reset(
-            new comphelper::OInterfaceContainerHelper3<XContentEventListener>( 
m_aEventListenerMutex ) );
-
+    std::unique_lock aGuard( m_aMutex );
 
-    m_pContentEventListeners->addInterface( Listener );
+    m_aContentEventListeners.addInterface( aGuard, Listener );
 }
 
 
@@ -489,10 +445,9 @@ void SAL_CALL
 BaseContent::removeContentEventListener(
     const Reference< XContentEventListener >& Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
-    if ( m_pContentEventListeners )
-        m_pContentEventListeners->removeInterface( Listener );
+    m_aContentEventListeners.removeInterface( aGuard, Listener );
 }
 
 
@@ -594,11 +549,9 @@ void SAL_CALL
 BaseContent::addPropertySetInfoChangeListener(
     const Reference< beans::XPropertySetInfoChangeListener >& Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
-    if( ! m_pPropertySetInfoChangeListeners )
-        m_pPropertySetInfoChangeListeners.reset( new 
comphelper::OInterfaceContainerHelper3<beans::XPropertySetInfoChangeListener>( 
m_aEventListenerMutex ) );
+    std::unique_lock aGuard( m_aMutex );
 
-    m_pPropertySetInfoChangeListeners->addInterface( Listener );
+    m_aPropertySetInfoChangeListeners.addInterface( aGuard, Listener );
 }
 
 
@@ -606,10 +559,9 @@ void SAL_CALL
 BaseContent::removePropertySetInfoChangeListener(
     const Reference< beans::XPropertySetInfoChangeListener >& Listener )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
-    if( m_pPropertySetInfoChangeListeners )
-        m_pPropertySetInfoChangeListeners->removeInterface( Listener );
+    m_aPropertySetInfoChangeListeners.removeInterface( aGuard, Listener );
 }
 
 
@@ -942,7 +894,7 @@ BaseContent::deleteContent( sal_Int32 nMyCommandIdentifier )
 
     if( m_pMyShell->remove( nMyCommandIdentifier,m_aUncPath ) )
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         m_nState |= Deleted;
     }
 }
@@ -1119,7 +1071,7 @@ void BaseContent::insert( sal_Int32 nMyCommandIdentifier,
     m_pMyShell->registerNotifier( m_aUncPath,this );
     m_pMyShell->insertDefaultProperties( m_aUncPath );
 
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     m_nState = FullFeatured;
 }
 
@@ -1134,80 +1086,80 @@ void BaseContent::endTask( sal_Int32 CommandId )
 std::optional<ContentEventNotifier>
 BaseContent::cDEL()
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     m_nState |= Deleted;
 
-    if( !m_pContentEventListeners )
+    if( m_aContentEventListeners.getLength(aGuard) == 0 )
         return {};
 
     return ContentEventNotifier( m_pMyShell,
                                   this,
                                   m_xContentIdentifier,
-                                  m_pContentEventListeners->getElements() );
+                                  m_aContentEventListeners.getElements(aGuard) 
);
 }
 
 
 std::optional<ContentEventNotifier>
 BaseContent::cEXC( const OUString& aNewName )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     Reference< XContentIdentifier > xOldRef = m_xContentIdentifier;
     m_aUncPath = aNewName;
     m_xContentIdentifier = new FileContentIdentifier( aNewName );
 
-    if( !m_pContentEventListeners )
+    if( m_aContentEventListeners.getLength(aGuard) == 0 )
         return {};
     return ContentEventNotifier( m_pMyShell,
                                   this,
                                   m_xContentIdentifier,
                                   xOldRef,
-                                  m_pContentEventListeners->getElements() );
+                                  m_aContentEventListeners.getElements(aGuard) 
);
 }
 
 
 std::optional<ContentEventNotifier>
 BaseContent::cCEL()
 {
-    osl::MutexGuard aGuard( m_aMutex );
-    if( !m_pContentEventListeners )
+    std::unique_lock aGuard( m_aMutex );
+    if( m_aContentEventListeners.getLength(aGuard) == 0 )
         return {};
     return ContentEventNotifier( m_pMyShell,
                                       this,
                                       m_xContentIdentifier,
-                                      m_pContentEventListeners->getElements() 
);
+                                      
m_aContentEventListeners.getElements(aGuard) );
 }
 
 std::optional<PropertySetInfoChangeNotifier>
 BaseContent::cPSL()
 {
-    osl::MutexGuard aGuard( m_aMutex );
-    if( !m_pPropertySetInfoChangeListeners  )
+    std::unique_lock aGuard( m_aMutex );
+    if( m_aPropertySetInfoChangeListeners.getLength(aGuard) == 0  )
         return {};
-    return PropertySetInfoChangeNotifier( this, 
m_pPropertySetInfoChangeListeners->getElements() );
+    return PropertySetInfoChangeNotifier( this, 
m_aPropertySetInfoChangeListeners.getElements(aGuard) );
 }
 
 
 std::optional<PropertyChangeNotifier>
 BaseContent::cPCL()
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     if (!m_pPropertyListener)
         return {};
 
-    const std::vector< OUString > seqNames = 
m_pPropertyListener->getContainedTypes();
+    const std::vector< OUString > seqNames = 
m_pPropertyListener->getContainedTypes(aGuard);
     if( seqNames.empty() )
         return {};
 
     ListenerMap listener;
     for( const auto& rName : seqNames )
     {
-        
comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener>* 
pContainer = m_pPropertyListener->getContainer(rName);
+        
comphelper::OInterfaceContainerHelper4<beans::XPropertiesChangeListener>* 
pContainer = m_pPropertyListener->getContainer(aGuard, rName);
         if (!pContainer)
             continue;
-        listener[rName] = pContainer->getElements();
+        listener[rName] = pContainer->getElements(aGuard);
     }
 
     return PropertyChangeNotifier( this, std::move(listener) );
diff --git a/ucb/source/ucp/file/bc.hxx b/ucb/source/ucp/file/bc.hxx
index fff14a09ecbe..a9afbdd5002c 100644
--- a/ucb/source/ucp/file/bc.hxx
+++ b/ucb/source/ucp/file/bc.hxx
@@ -19,10 +19,10 @@
 
 #pragma once
 
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <rtl/ustring.hxx>
 #include <cppuhelper/implbase.hxx>
-#include <comphelper/interfacecontainer3.hxx>
+#include <comphelper/interfacecontainer4.hxx>
 #include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/ucb/XCommandProcessor.hpp>
@@ -203,12 +203,10 @@ namespace fileaccess {
         bool                                                  m_bFolder;
         sal_uInt16                                            m_nState;
 
-        osl::Mutex                         m_aMutex;
-
-        osl::Mutex                          m_aEventListenerMutex;
-        
std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::lang::XEventListener>>
   m_pDisposeEventListeners;
-        
std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::ucb::XContentEventListener>>
 m_pContentEventListeners;
-        
std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::beans::XPropertySetInfoChangeListener>>
 m_pPropertySetInfoChangeListeners;
+        std::mutex                         m_aMutex;
+        comphelper::OInterfaceContainerHelper4<css::lang::XEventListener>   
m_aDisposeEventListeners;
+        
comphelper::OInterfaceContainerHelper4<css::ucb::XContentEventListener> 
m_aContentEventListeners;
+        
comphelper::OInterfaceContainerHelper4<css::beans::XPropertySetInfoChangeListener>
 m_aPropertySetInfoChangeListeners;
         std::unique_ptr<PropertyListeners>                  
m_pPropertyListener;
 
 
diff --git a/ucb/source/ucp/file/filnot.cxx b/ucb/source/ucp/file/filnot.cxx
index 013311e2d1bc..d384dc0ea717 100644
--- a/ucb/source/ucp/file/filnot.cxx
+++ b/ucb/source/ucp/file/filnot.cxx
@@ -91,7 +91,7 @@ void ContentEventNotifier::notifyRemoved( const OUString& 
aChildName ) const
 
     rtl::Reference<BaseContent> pp = new BaseContent( 
m_pMyShell,xChildId,aChildName );
     {
-        osl::MutexGuard aGuard( pp->m_aMutex );
+        std::unique_lock aGuard( pp->m_aMutex );
         pp->m_nState |= BaseContent::Deleted;
     }
 

Reply via email to