ucbhelper/source/client/content.cxx |   91 ++++++++++++++++++++----------------
 1 file changed, 52 insertions(+), 39 deletions(-)

New commits:
commit 9d0a8f7a2e3e473ebb3042f90dd82696dd8705da
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu May 5 22:50:16 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri May 6 20:57:08 2022 +0200

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

diff --git a/ucbhelper/source/client/content.cxx 
b/ucbhelper/source/client/content.cxx
index dfe2a9103add..948c4848c6f4 100644
--- a/ucbhelper/source/client/content.cxx
+++ b/ucbhelper/source/client/content.cxx
@@ -23,7 +23,7 @@
 
 #include <o3tl/unreachable.hxx>
 #include <osl/diagnose.h>
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <sal/log.hxx>
 #include <salhelper/simplereferenceobject.hxx>
 #include <cppuhelper/weak.hxx>
@@ -159,11 +159,13 @@ friend ContentEventListener_Impl;
     Reference< XCommandProcessor >          m_xCommandProcessor;
     Reference< XCommandEnvironment >    m_xEnv;
     Reference< XContentEventListener >  m_xContentEventListener;
-    mutable osl::Mutex                  m_aMutex;
+    mutable std::mutex                  m_aMutex;
 
 private:
     void reinit( const Reference< XContent >& xContent );
     void disposing(const EventObject& Source);
+    Reference< XContent > getContent_NoLock();
+    const OUString& getURL_NoLock() const;
 
 public:
     Content_Impl() {};
@@ -1089,7 +1091,7 @@ Content_Impl::Content_Impl( const Reference< 
XComponentContext >& rCtx,
 
 void Content_Impl::reinit( const Reference< XContent >& xContent )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
 
     m_xCommandProcessor = nullptr;
 
@@ -1114,14 +1116,14 @@ void Content_Impl::reinit( const Reference< XContent >& 
xContent )
 #if OSL_DEBUG_LEVEL > 0
         // Only done on demand in product version for performance reasons,
         // but a nice debug helper.
-        getURL();
+        getURL_NoLock();
 #endif
     }
     else
     {
         // We need m_xContent's URL in order to be able to create the
         // content object again if demanded ( --> Content_Impl::getContent() )
-        getURL();
+        getURL_NoLock();
 
         m_xContent = nullptr;
     }
@@ -1149,7 +1151,7 @@ void Content_Impl::disposing( const EventObject& Source )
     Reference<XContent> xContent;
 
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
         if(Source.Source != m_xContent)
             return;
 
@@ -1177,53 +1179,64 @@ const OUString& Content_Impl::getURL() const
 {
     if ( m_aURL.isEmpty() && m_xContent.is() )
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
 
-        if ( m_aURL.isEmpty() && m_xContent.is() )
-        {
-            Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
-            if ( xId.is() )
-                m_aURL = xId->getContentIdentifier();
-        }
+        return getURL_NoLock();
     }
 
     return m_aURL;
 }
 
+const OUString& Content_Impl::getURL_NoLock() const
+{
+    if ( m_aURL.isEmpty() && m_xContent.is() )
+    {
+        Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
+        if ( xId.is() )
+            m_aURL = xId->getContentIdentifier();
+    }
+
+    return m_aURL;
+}
 
 Reference< XContent > Content_Impl::getContent()
 {
     if ( !m_xContent.is() && !m_aURL.isEmpty() )
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
+        return getContent_NoLock();
+    }
+    return m_xContent;
+}
 
-        if ( !m_xContent.is() && !m_aURL.isEmpty() )
-        {
-            Reference< XUniversalContentBroker > pBroker(
-                UniversalContentBroker::create( getComponentContext() ) );
+Reference< XContent > Content_Impl::getContent_NoLock()
+{
+    if ( !m_xContent.is() && !m_aURL.isEmpty() )
+    {
+        Reference< XUniversalContentBroker > pBroker(
+            UniversalContentBroker::create( getComponentContext() ) );
 
-            OSL_ENSURE( pBroker->queryContentProviders().hasElements(),
-                        "Content Broker not configured (no providers)!" );
+        OSL_ENSURE( pBroker->queryContentProviders().hasElements(),
+                    "Content Broker not configured (no providers)!" );
 
-            Reference< XContentIdentifier > xId
-                = pBroker->createContentIdentifier( m_aURL );
+        Reference< XContentIdentifier > xId
+            = pBroker->createContentIdentifier( m_aURL );
 
-            OSL_ENSURE( xId.is(), "No Content Identifier!" );
+        OSL_ENSURE( xId.is(), "No Content Identifier!" );
 
-            if ( xId.is() )
+        if ( xId.is() )
+        {
+            try
             {
-                try
-                {
-                    m_xContent = pBroker->queryContent( xId );
-                }
-                catch ( IllegalIdentifierException const & )
-                {
-                }
-
-                if ( m_xContent.is() )
-                    m_xContent->addContentEventListener(
-                        m_xContentEventListener );
+                m_xContent = pBroker->queryContent( xId );
             }
+            catch ( IllegalIdentifierException const & )
+            {
+            }
+
+            if ( m_xContent.is() )
+                m_xContent->addContentEventListener(
+                    m_xContentEventListener );
         }
     }
 
@@ -1235,10 +1248,10 @@ Reference< XCommandProcessor > 
Content_Impl::getCommandProcessor()
 {
     if ( !m_xCommandProcessor.is() )
     {
-        osl::MutexGuard aGuard( m_aMutex );
+        std::unique_lock aGuard( m_aMutex );
 
         if ( !m_xCommandProcessor.is() )
-            m_xCommandProcessor.set( getContent(), UNO_QUERY );
+            m_xCommandProcessor.set( getContent_NoLock(), UNO_QUERY );
     }
 
     return m_xCommandProcessor;
@@ -1266,7 +1279,7 @@ inline const Reference< XCommandEnvironment >&
 inline void Content_Impl::setEnvironment(
                         const Reference< XCommandEnvironment >& xNewEnv )
 {
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     m_xEnv = xNewEnv;
 }
 
@@ -1274,7 +1287,7 @@ inline void Content_Impl::setEnvironment(
 void Content_Impl::inserted()
 {
     // URL might have changed during 'insert' => recalculate in next getURL()
-    osl::MutexGuard aGuard( m_aMutex );
+    std::unique_lock aGuard( m_aMutex );
     m_aURL.clear();
 }
 

Reply via email to