sw/inc/unochart.hxx                 |   12 +++---
 sw/source/core/unocore/unochart.cxx |   63 ++++++++++++++++++------------------
 sw/source/core/unocore/unofield.cxx |   36 +++++++++-----------
 3 files changed, 54 insertions(+), 57 deletions(-)

New commits:
commit 94e021c5e1f1fdb19d18fe8f5be7b5b4e5b841a7
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Dec 21 18:54:53 2021 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Sat Jan 1 07:15:13 2022 +0100

    osl::Mutex->std::mutex in SwChartData
    
    Change-Id: I1bc85e4c8ac4945e13063793203fd308526263a6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127814
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/inc/unochart.hxx b/sw/inc/unochart.hxx
index 632efdee5530..2df27f9dbda2 100644
--- a/sw/inc/unochart.hxx
+++ b/sw/inc/unochart.hxx
@@ -39,7 +39,7 @@
 #include <com/sun/star/util/XModifiable.hpp>
 #include <com/sun/star/util/XModifyListener.hpp>
 
-#include <comphelper/interfacecontainer3.hxx>
+#include <comphelper/interfacecontainer4.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/weakref.hxx>
 
@@ -125,7 +125,7 @@ class SwChartDataProvider final :
     // all tables of the document.
     mutable Map_Set_DataSequenceRef_t       m_aDataSequences;
 
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
m_aEventListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_aEventListeners;
     const SwDoc *                           m_pDoc;
     bool                                    m_bDisposed;
 
@@ -232,8 +232,8 @@ class SwChartDataSequence final :
     public SvtListener
 {
     SwFrameFormat* m_pFormat;
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
m_aEvtListeners;
-    ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener> 
m_aModifyListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_aEvtListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> 
m_aModifyListeners;
     css::chart2::data::DataSequenceRole               m_aRole;
 
     OUString  m_aRowLabelText;
@@ -328,8 +328,8 @@ SwChartLabeledDataSequenceBaseClass;
 class SwChartLabeledDataSequence final :
     public SwChartLabeledDataSequenceBaseClass
 {
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
m_aEventListeners;
-    ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener> 
m_aModifyListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_aEventListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> 
m_aModifyListeners;
 
     css::uno::Reference< css::chart2::data::XDataSequence >     m_xData;
     css::uno::Reference< css::chart2::data::XDataSequence >     m_xLabels;
diff --git a/sw/source/core/unocore/unochart.cxx 
b/sw/source/core/unocore/unochart.cxx
index ef60775a6e3d..d1bc07765758 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -25,7 +25,7 @@
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 #include <cppuhelper/supportsservice.hxx>
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <vcl/svapp.hxx>
 
 #include "XMLRangeHelper.hxx"
@@ -149,14 +149,14 @@ IMPL_LINK_NOARG( SwChartLockController_Helper, 
DoUnlockAllCharts, Timer *, void
     UnlockAllCharts();
 }
 
-static osl::Mutex &    GetChartMutex()
+static std::mutex &    GetChartMutex()
 {
-    static osl::Mutex   aMutex;
+    static std::mutex aMutex;
     return aMutex;
 }
 
 static void LaunchModifiedEvent(
-        ::comphelper::OInterfaceContainerHelper3<util::XModifyListener> &rICH,
+        ::comphelper::OInterfaceContainerHelper4<util::XModifyListener> &rICH,
         const uno::Reference< uno::XInterface > &rxI )
 {
     lang::EventObject aEvtObj( rxI );
@@ -498,7 +498,6 @@ static void SortSubranges( uno::Sequence< OUString > 
&rSubRanges, bool bCmpByCol
 }
 
 SwChartDataProvider::SwChartDataProvider( const SwDoc& rSwDoc ) :
-    m_aEventListeners( GetChartMutex() ),
     m_pDoc( &rSwDoc )
 {
     m_bDisposed = false;
@@ -1357,7 +1356,7 @@ void SAL_CALL SwChartDataProvider::dispose(  )
 {
     bool bMustDispose( false );
     {
-        osl::MutexGuard  aGuard( GetChartMutex() );
+        std::unique_lock aGuard( GetChartMutex() );
         bMustDispose = !m_bDisposed;
         if (!m_bDisposed)
             m_bDisposed = true;
@@ -1375,13 +1374,14 @@ void SAL_CALL SwChartDataProvider::dispose(  )
 
     // require listeners to release references to this object
     lang::EventObject aEvtObj( static_cast< chart2::data::XDataProvider * 
>(this) );
-    m_aEventListeners.disposeAndClear( aEvtObj );
+    std::unique_lock aGuard( GetChartMutex() );
+    m_aEventListeners.disposeAndClear( aGuard, aEvtObj );
 }
 
 void SAL_CALL SwChartDataProvider::addEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEventListeners.addInterface( rxListener );
 }
@@ -1389,7 +1389,7 @@ void SAL_CALL SwChartDataProvider::addEventListener(
 void SAL_CALL SwChartDataProvider::removeEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEventListeners.removeInterface( rxListener );
 }
@@ -1772,8 +1772,6 @@ SwChartDataSequence::SwChartDataSequence(
         SwFrameFormat& rTableFormat,
         const std::shared_ptr<SwUnoCursor>& pTableCursor ) :
     m_pFormat(&rTableFormat),
-    m_aEvtListeners( GetChartMutex() ),
-    m_aModifyListeners( GetChartMutex() ),
     m_aRowLabelText( SwResId( STR_CHART2_ROW_LABEL_TEXT ) ),
     m_aColLabelText( SwResId( STR_CHART2_COL_LABEL_TEXT ) ),
     m_xDataProvider( &rProvider ),
@@ -1819,8 +1817,6 @@ SwChartDataSequence::SwChartDataSequence( const 
SwChartDataSequence &rObj ) :
     SwChartDataSequenceBaseClass(rObj),
     SvtListener(),
     m_pFormat( rObj.m_pFormat ),
-    m_aEvtListeners( GetChartMutex() ),
-    m_aModifyListeners( GetChartMutex() ),
     m_aRole( rObj.m_aRole ),
     m_aRowLabelText( SwResId(STR_CHART2_ROW_LABEL_TEXT) ),
     m_aColLabelText( SwResId(STR_CHART2_COL_LABEL_TEXT) ),
@@ -2193,7 +2189,7 @@ void SAL_CALL SwChartDataSequence::setModified(
 void SAL_CALL SwChartDataSequence::addModifyListener(
         const uno::Reference< util::XModifyListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aModifyListeners.addInterface( rxListener );
 }
@@ -2201,7 +2197,7 @@ void SAL_CALL SwChartDataSequence::addModifyListener(
 void SAL_CALL SwChartDataSequence::removeModifyListener(
         const uno::Reference< util::XModifyListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aModifyListeners.removeInterface( rxListener );
 }
@@ -2220,7 +2216,7 @@ void SAL_CALL SwChartDataSequence::dispose(  )
 {
     bool bMustDispose( false );
     {
-        osl::MutexGuard  aGuard( GetChartMutex() );
+        std::unique_lock aGuard( GetChartMutex() );
         bMustDispose = !m_bDisposed;
         if (!m_bDisposed)
             m_bDisposed = true;
@@ -2267,14 +2263,16 @@ void SAL_CALL SwChartDataSequence::dispose(  )
 
     // require listeners to release references to this object
     lang::EventObject aEvtObj( static_cast< chart2::data::XDataSequence * 
>(this) );
-    m_aModifyListeners.disposeAndClear( aEvtObj );
-    m_aEvtListeners.disposeAndClear( aEvtObj );
+    std::unique_lock aGuard( GetChartMutex() );
+    m_aModifyListeners.disposeAndClear( aGuard, aEvtObj );
+    aGuard.lock();
+    m_aEvtListeners.disposeAndClear( aGuard, aEvtObj );
 }
 
 void SAL_CALL SwChartDataSequence::addEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEvtListeners.addInterface( rxListener );
 }
@@ -2282,7 +2280,7 @@ void SAL_CALL SwChartDataSequence::addEventListener(
 void SAL_CALL SwChartDataSequence::removeEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEvtListeners.removeInterface( rxListener );
 }
@@ -2504,9 +2502,7 @@ void SwChartDataSequence::ExtendTo( bool bExtendCol,
     }
 }
 
-SwChartLabeledDataSequence::SwChartLabeledDataSequence() :
-    m_aEventListeners( GetChartMutex() ),
-    m_aModifyListeners( GetChartMutex() )
+SwChartLabeledDataSequence::SwChartLabeledDataSequence()
 {
     m_bDisposed = false;
 }
@@ -2629,14 +2625,17 @@ uno::Sequence< OUString > SAL_CALL 
SwChartLabeledDataSequence::getSupportedServi
 void SAL_CALL SwChartLabeledDataSequence::disposing(
         const lang::EventObject& rSource )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     uno::Reference< uno::XInterface > xRef( rSource.Source );
     if (xRef == m_xData)
         m_xData.clear();
     if (xRef == m_xLabels)
         m_xLabels.clear();
     if (!m_xData.is() && !m_xLabels.is())
+    {
+        aGuard.unlock();
         dispose();
+    }
 }
 
 void SAL_CALL SwChartLabeledDataSequence::modified(
@@ -2651,7 +2650,7 @@ void SAL_CALL SwChartLabeledDataSequence::modified(
 void SAL_CALL SwChartLabeledDataSequence::addModifyListener(
         const uno::Reference< util::XModifyListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aModifyListeners.addInterface( rxListener );
 }
@@ -2659,7 +2658,7 @@ void SAL_CALL 
SwChartLabeledDataSequence::addModifyListener(
 void SAL_CALL SwChartLabeledDataSequence::removeModifyListener(
         const uno::Reference< util::XModifyListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aModifyListeners.removeInterface( rxListener );
 }
@@ -2668,7 +2667,7 @@ void SAL_CALL SwChartLabeledDataSequence::dispose(  )
 {
     bool bMustDispose( false );
     {
-        osl::MutexGuard  aGuard( GetChartMutex() );
+        std::unique_lock aGuard( GetChartMutex() );
         bMustDispose = !m_bDisposed;
         if (!m_bDisposed)
             m_bDisposed = true;
@@ -2679,15 +2678,17 @@ void SAL_CALL SwChartLabeledDataSequence::dispose(  )
 
         // require listeners to release references to this object
         lang::EventObject aEvtObj( static_cast< 
chart2::data::XLabeledDataSequence * >(this) );
-        m_aModifyListeners.disposeAndClear( aEvtObj );
-        m_aEventListeners.disposeAndClear( aEvtObj );
+        std::unique_lock aGuard( GetChartMutex() );
+        m_aModifyListeners.disposeAndClear( aGuard, aEvtObj );
+        aGuard.lock();
+        m_aEventListeners.disposeAndClear( aGuard, aEvtObj );
     }
 }
 
 void SAL_CALL SwChartLabeledDataSequence::addEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEventListeners.addInterface( rxListener );
 }
@@ -2695,7 +2696,7 @@ void SAL_CALL 
SwChartLabeledDataSequence::addEventListener(
 void SAL_CALL SwChartLabeledDataSequence::removeEventListener(
         const uno::Reference< lang::XEventListener >& rxListener )
 {
-    osl::MutexGuard  aGuard( GetChartMutex() );
+    std::unique_lock aGuard( GetChartMutex() );
     if (!m_bDisposed && rxListener.is())
         m_aEventListeners.removeInterface( rxListener );
 }
commit 3f1886a2d00d8819b94220f0436f3a134041bcba
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Dec 21 19:01:13 2021 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Sat Jan 1 07:15:06 2022 +0100

    osl::Mutex->std::mutex in SwXTextField*
    
    Change-Id: I80dde4f44dd3d2f701a246dec850f7560207ffee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127815
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index 9b2d96f679ee..717776dbc6f0 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -43,7 +43,7 @@
 #include <sfx2/linkmgr.hxx>
 #include <editsh.hxx>
 #include <viewsh.hxx>
-#include <comphelper/interfacecontainer3.hxx>
+#include <comphelper/interfacecontainer4.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <comphelper/string.hxx>
 #include <cppuhelper/supportsservice.hxx>
@@ -81,7 +81,7 @@
 #include <svx/dataaccessdescriptor.hxx>
 #include <o3tl/any.hxx>
 #include <o3tl/safeint.hxx>
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <vcl/svapp.hxx>
 #include <textapi.hxx>
 #include <fmtmeta.hxx>
@@ -405,11 +405,11 @@ class SwXFieldMaster::Impl
     : public SvtListener
 {
 private:
-    ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper3
+    std::mutex m_Mutex; // just for OInterfaceContainerHelper3
 
 public:
     uno::WeakReference<uno::XInterface> m_wThis;
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
m_EventListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
 
     SwDoc*          m_pDoc;
     SwFieldType* m_pType;
@@ -426,8 +426,7 @@ public:
     sal_Int32       m_nParam2;
 
     Impl(SwPageDesc* const pPageDesc, SwDoc* pDoc, SwFieldIds nResId)
-        : m_EventListeners(m_Mutex)
-        , m_pDoc(pDoc)
+        : m_pDoc(pDoc)
         , m_pType(nullptr)
         , m_nResTypeId(nResId)
         , m_fParam1(0.0)
@@ -439,8 +438,7 @@ public:
     }
 
     Impl(SwFieldType* const pType, SwDoc* pDoc, SwFieldIds nResId)
-        : m_EventListeners(m_Mutex)
-        , m_pDoc(pDoc)
+        : m_pDoc(pDoc)
         , m_pType(pType)
         , m_nResTypeId(nResId)
         , m_fParam1(0.0)
@@ -995,7 +993,8 @@ void SwXFieldMaster::Impl::Notify(const SfxHint& rHint)
             return;
         }
         lang::EventObject const ev(xThis);
-        m_EventListeners.disposeAndClear(ev);
+        std::unique_lock aGuard(m_Mutex);
+        m_EventListeners.disposeAndClear(aGuard, ev);
     }
 }
 
@@ -1085,13 +1084,13 @@ class SwXTextField::Impl
     : public SvtListener
 {
 private:
-    ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper3
+    std::mutex m_Mutex; // just for OInterfaceContainerHelper3
     SwFieldType* m_pFieldType;
     SwFormatField* m_pFormatField;
 
 public:
     uno::WeakReference<uno::XInterface> m_wThis;
-    ::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> 
m_EventListeners;
+    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
 
     SwDoc* m_pDoc;
     rtl::Reference<SwTextAPIObject> m_xTextObject;
@@ -1104,7 +1103,6 @@ public:
     Impl(SwDoc *const pDoc, SwFormatField *const pFormat, SwServiceType 
nServiceId)
         : m_pFieldType(nullptr)
         , m_pFormatField(pFormat)
-        , m_EventListeners(m_Mutex)
         , m_pDoc(pDoc)
         , m_bIsDescriptor(pFormat == nullptr)
         , m_bCallUpdate(false)
@@ -2611,7 +2609,8 @@ void SwXTextField::Impl::Invalidate()
         return;
     }
     lang::EventObject const ev(xThis);
-    m_EventListeners.disposeAndClear(ev);
+    std::unique_lock aGuard(m_Mutex);
+    m_EventListeners.disposeAndClear(aGuard, ev);
 }
 
 void SwXTextField::Impl::Notify(const SfxHint& rHint)
@@ -2827,13 +2826,9 @@ sal_Bool SwXTextFieldMasters::hasElements()
 
 class SwXTextFieldTypes::Impl
 {
-private:
-    ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper3
-
 public:
-    ::comphelper::OInterfaceContainerHelper3<util::XRefreshListener> 
m_RefreshListeners;
-
-    Impl() : m_RefreshListeners(m_Mutex) { }
+    std::mutex m_Mutex; // just for OInterfaceContainerHelper3
+    ::comphelper::OInterfaceContainerHelper4<util::XRefreshListener> 
m_RefreshListeners;
 };
 
 OUString SwXTextFieldTypes::getImplementationName()
@@ -2866,7 +2861,8 @@ void SwXTextFieldTypes::Invalidate()
 {
     SwUnoCollection::Invalidate();
     lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
-    m_pImpl->m_RefreshListeners.disposeAndClear(ev);
+    std::unique_lock aGuard(m_pImpl->m_Mutex);
+    m_pImpl->m_RefreshListeners.disposeAndClear(aGuard, ev);
 }
 
 uno::Reference< container::XEnumeration >  
SwXTextFieldTypes::createEnumeration()

Reply via email to