comphelper/source/misc/weakeventlistener.cxx      |    2 
 include/comphelper/weakeventlistener.hxx          |   13 +--
 sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx |   82 ++++++++++++----------
 sd/source/ui/slidesorter/cache/SlsBitmapCache.hxx |   12 ++-
 4 files changed, 63 insertions(+), 46 deletions(-)

New commits:
commit 2767caa7958a0c98117494bf09ce5333af679c14
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Feb 17 14:00:07 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Feb 19 07:33:47 2023 +0000

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

diff --git a/comphelper/source/misc/weakeventlistener.cxx 
b/comphelper/source/misc/weakeventlistener.cxx
index e8ce46590559..0543816d0593 100644
--- a/comphelper/source/misc/weakeventlistener.cxx
+++ b/comphelper/source/misc/weakeventlistener.cxx
@@ -55,7 +55,7 @@ namespace comphelper
     }
 
 
-    void SAL_CALL OWeakEventListenerAdapter::disposing( )
+    void OWeakEventListenerAdapter::disposing( std::unique_lock<std::mutex>& 
/*rGuard*/ )
     {
         Reference< XComponent > xBroadcaster( getBroadcaster( ), UNO_QUERY );
         OSL_ENSURE( xBroadcaster.is(), "OWeakEventListenerAdapter::disposing: 
broadcaster is invalid in the meantime! How this?" );
diff --git a/include/comphelper/weakeventlistener.hxx 
b/include/comphelper/weakeventlistener.hxx
index d64f302d8066..c4b4e79704c4 100644
--- a/include/comphelper/weakeventlistener.hxx
+++ b/include/comphelper/weakeventlistener.hxx
@@ -21,7 +21,7 @@
 #define INCLUDED_COMPHELPER_WEAKEVENTLISTENER_HXX
 
 #include <config_options.h>
-#include <cppuhelper/compbase.hxx>
+#include <comphelper/compbase.hxx>
 #include <cppuhelper/basemutex.hxx>
 #include <cppuhelper/weakref.hxx>
 #include <comphelper/comphelperdllapi.h>
@@ -44,7 +44,7 @@ namespace comphelper
         holds it's listener hard. The adapter itself knows the real listener 
as weak reference,
         thus not affecting its life time.</p>
     */
-    class OWeakListenerAdapterBase : public cppu::BaseMutex
+    class OWeakListenerAdapterBase
     {
     private:
         css::uno::WeakReference< css::uno::XInterface >
@@ -98,7 +98,7 @@ namespace comphelper
         as this can't be done in a generic way</p>
     */
     class OWeakListenerAdapter
-            :public ::cppu::WeakComponentImplHelper< LISTENER >
+            :public ::comphelper::WeakComponentImplHelper< LISTENER >
             ,public OWeakListenerAdapterBase
     {
     protected:
@@ -123,7 +123,7 @@ namespace comphelper
     protected:
         // OComponentHelper overridables
         // to be overridden, again - the derived class should revoke the 
listener from the broadcaster
-        virtual void SAL_CALL disposing( ) override = 0;
+        virtual void disposing( std::unique_lock<std::mutex>& rGuard ) 
override = 0;
     };
 
 
@@ -147,7 +147,7 @@ namespace comphelper
 
     private:
         using OWeakEventListenerAdapter_Base::disposing;
-        virtual void SAL_CALL disposing( ) override;
+        virtual void disposing( std::unique_lock<std::mutex>& rGuard ) 
override;
     };
 
 
@@ -159,8 +159,7 @@ namespace comphelper
         const css::uno::Reference< css::uno::XWeak >& _rxListener,
         const css::uno::Reference< BROADCASTER >& _rxBroadcaster
     )
-        : ::cppu::WeakComponentImplHelper< LISTENER >( m_aMutex )
-        , OWeakListenerAdapterBase( _rxListener, _rxBroadcaster )
+        : OWeakListenerAdapterBase( _rxListener, _rxBroadcaster )
     {
     }
 
commit 801cbe5410d44805945c2be616b284888a1e1b80
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Feb 17 15:30:58 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Feb 19 07:33:34 2023 +0000

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

diff --git a/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx 
b/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx
index 87c727408cfe..89acdc564bf5 100644
--- a/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx
+++ b/sd/source/ui/slidesorter/cache/SlsBitmapCache.cxx
@@ -140,7 +140,7 @@ BitmapCache::~BitmapCache()
 
 void BitmapCache::Clear()
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     mpBitmapContainer->clear();
     mnNormalCacheSize = 0;
@@ -150,7 +150,7 @@ void BitmapCache::Clear()
 
 bool BitmapCache::HasBitmap (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     return (iEntry != mpBitmapContainer->end()
@@ -159,7 +159,7 @@ bool BitmapCache::HasBitmap (const CacheKey& rKey)
 
 bool BitmapCache::BitmapIsUpToDate (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     bool bIsUpToDate = false;
     CacheBitmapContainer::iterator aIterator (mpBitmapContainer->find(rKey));
@@ -171,14 +171,14 @@ bool BitmapCache::BitmapIsUpToDate (const CacheKey& rKey)
 
 BitmapEx BitmapCache::GetBitmap (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry == mpBitmapContainer->end())
     {
         // Create an empty bitmap for the given key that acts as placeholder
         // until we are given the real one.  Mark it as not being up to date.
-        SetBitmap(rKey, BitmapEx(), false);
+        SetBitmap(aGuard, rKey, BitmapEx(), false);
         iEntry = mpBitmapContainer->find(rKey);
         iEntry->second.SetUpToDate(false);
     }
@@ -189,9 +189,9 @@ BitmapEx BitmapCache::GetBitmap (const CacheKey& rKey)
         // Maybe we have to decompress the preview.
         if ( ! iEntry->second.HasPreview() && iEntry->second.HasReplacement())
         {
-            UpdateCacheSize(iEntry->second, REMOVE);
+            UpdateCacheSize(aGuard, iEntry->second, REMOVE);
             iEntry->second.Decompress();
-            UpdateCacheSize(iEntry->second, ADD);
+            UpdateCacheSize(aGuard, iEntry->second, ADD);
         }
     }
     return iEntry->second.GetPreview();
@@ -199,7 +199,7 @@ BitmapEx BitmapCache::GetBitmap (const CacheKey& rKey)
 
 BitmapEx BitmapCache::GetMarkedBitmap (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end())
@@ -213,19 +213,19 @@ BitmapEx BitmapCache::GetMarkedBitmap (const CacheKey& 
rKey)
 
 void BitmapCache::ReleaseBitmap (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator aIterator (mpBitmapContainer->find(rKey));
     if (aIterator != mpBitmapContainer->end())
     {
-        UpdateCacheSize(aIterator->second, REMOVE);
+        UpdateCacheSize(aGuard, aIterator->second, REMOVE);
         mpBitmapContainer->erase(aIterator);
     }
 }
 
 bool BitmapCache::InvalidateBitmap (const CacheKey& rKey)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end())
@@ -236,9 +236,9 @@ bool BitmapCache::InvalidateBitmap (const CacheKey& rKey)
         // preview itself is kept until a new one is created.
         if (iEntry->second.HasPreview())
         {
-            UpdateCacheSize(iEntry->second, REMOVE);
+            UpdateCacheSize(aGuard, iEntry->second, REMOVE);
             iEntry->second.Invalidate();
-            UpdateCacheSize(iEntry->second, ADD);
+            UpdateCacheSize(aGuard, iEntry->second, ADD);
         }
         return true;
     }
@@ -248,13 +248,13 @@ bool BitmapCache::InvalidateBitmap (const CacheKey& rKey)
 
 void BitmapCache::InvalidateCache()
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     for (auto& rEntry : *mpBitmapContainer)
     {
         rEntry.second.Invalidate();
     }
-    ReCalculateTotalCacheSize();
+    ReCalculateTotalCacheSize(aGuard);
 }
 
 void BitmapCache::SetBitmap (
@@ -262,12 +262,20 @@ void BitmapCache::SetBitmap (
     const BitmapEx& rPreview,
     bool bIsPrecious)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
+    SetBitmap(aGuard, rKey, rPreview, bIsPrecious);
+}
 
+void BitmapCache::SetBitmap (
+    std::unique_lock<std::mutex>& rGuard,
+    const CacheKey& rKey,
+    const BitmapEx& rPreview,
+    bool bIsPrecious)
+{
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end())
     {
-        UpdateCacheSize(iEntry->second, REMOVE);
+        UpdateCacheSize(rGuard, iEntry->second, REMOVE);
         iEntry->second.SetPreview(rPreview);
         iEntry->second.SetUpToDate(true);
         iEntry->second.SetAccessTime(mnCurrentAccessTime++);
@@ -281,37 +289,37 @@ void BitmapCache::SetBitmap (
     }
 
     if (iEntry != mpBitmapContainer->end())
-        UpdateCacheSize(iEntry->second, ADD);
+        UpdateCacheSize(rGuard, iEntry->second, ADD);
 }
 
 void BitmapCache::SetMarkedBitmap (
     const CacheKey& rKey,
     const BitmapEx& rPreview)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end())
     {
-        UpdateCacheSize(iEntry->second, REMOVE);
+        UpdateCacheSize(aGuard, iEntry->second, REMOVE);
         iEntry->second.SetMarkedPreview(rPreview);
         iEntry->second.SetAccessTime(mnCurrentAccessTime++);
-        UpdateCacheSize(iEntry->second, ADD);
+        UpdateCacheSize(aGuard, iEntry->second, ADD);
     }
 }
 
 void BitmapCache::SetPrecious (const CacheKey& rKey, bool bIsPrecious)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end())
     {
         if (iEntry->second.IsPrecious() != bIsPrecious)
         {
-            UpdateCacheSize(iEntry->second, REMOVE);
+            UpdateCacheSize(aGuard, iEntry->second, REMOVE);
             iEntry->second.SetPrecious(bIsPrecious);
-            UpdateCacheSize(iEntry->second, ADD);
+            UpdateCacheSize(aGuard, iEntry->second, ADD);
         }
     }
     else if (bIsPrecious)
@@ -320,14 +328,18 @@ void BitmapCache::SetPrecious (const CacheKey& rKey, bool 
bIsPrecious)
             rKey,
             CacheEntry(BitmapEx(), mnCurrentAccessTime++, bIsPrecious)
             ).first;
-        UpdateCacheSize(iEntry->second, ADD);
+        UpdateCacheSize(aGuard, iEntry->second, ADD);
     }
 }
 
 void BitmapCache::ReCalculateTotalCacheSize()
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
+    ReCalculateTotalCacheSize(aGuard);
+}
 
+void BitmapCache::ReCalculateTotalCacheSize(std::unique_lock<std::mutex>& 
/*rGuard*/)
+{
     mnNormalCacheSize = 0;
     mnPreciousCacheSize = 0;
     for (const auto& rEntry : *mpBitmapContainer)
@@ -344,7 +356,7 @@ void BitmapCache::ReCalculateTotalCacheSize()
 
 void BitmapCache::Recycle (const BitmapCache& rCache)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     for (const auto& rOtherEntry : *rCache.mpBitmapContainer)
     {
@@ -355,20 +367,20 @@ void BitmapCache::Recycle (const BitmapCache& rCache)
                 rOtherEntry.first,
                 CacheEntry(mnCurrentAccessTime++, true)
                 ).first;
-            UpdateCacheSize(iEntry->second, ADD);
+            UpdateCacheSize(aGuard, iEntry->second, ADD);
         }
         if (iEntry != mpBitmapContainer->end())
         {
-            UpdateCacheSize(iEntry->second, REMOVE);
+            UpdateCacheSize(aGuard, iEntry->second, REMOVE);
             iEntry->second.Recycle(rOtherEntry.second);
-            UpdateCacheSize(iEntry->second, ADD);
+            UpdateCacheSize(aGuard, iEntry->second, ADD);
         }
     }
 }
 
 BitmapCache::CacheIndex BitmapCache::GetCacheIndex() const
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     // Create a copy of the bitmap container.
     SortableBitmapContainer aSortedContainer;
@@ -401,18 +413,18 @@ void BitmapCache::Compress (
     const CacheKey& rKey,
     const std::shared_ptr<BitmapCompressor>& rpCompressor)
 {
-    ::osl::MutexGuard aGuard (maMutex);
+    std::unique_lock aGuard (maMutex);
 
     CacheBitmapContainer::iterator iEntry (mpBitmapContainer->find(rKey));
     if (iEntry != mpBitmapContainer->end() && iEntry->second.HasPreview())
     {
-        UpdateCacheSize(iEntry->second, REMOVE);
+        UpdateCacheSize(aGuard, iEntry->second, REMOVE);
         iEntry->second.Compress(rpCompressor);
-        UpdateCacheSize(iEntry->second, ADD);
+        UpdateCacheSize(aGuard, iEntry->second, ADD);
     }
 }
 
-void BitmapCache::UpdateCacheSize (const CacheEntry& rEntry, CacheOperation 
eOperation)
+void BitmapCache::UpdateCacheSize (std::unique_lock<std::mutex>& /*rGuard*/, 
const CacheEntry& rEntry, CacheOperation eOperation)
 {
     sal_Int32 nEntrySize (rEntry.GetMemorySize());
     sal_Int32& rCacheSize (rEntry.IsPrecious() ? mnPreciousCacheSize : 
mnNormalCacheSize);
diff --git a/sd/source/ui/slidesorter/cache/SlsBitmapCache.hxx 
b/sd/source/ui/slidesorter/cache/SlsBitmapCache.hxx
index 98b0bcb53728..cf527832497c 100644
--- a/sd/source/ui/slidesorter/cache/SlsBitmapCache.hxx
+++ b/sd/source/ui/slidesorter/cache/SlsBitmapCache.hxx
@@ -20,7 +20,7 @@
 #pragma once
 
 #include <vcl/bitmapex.hxx>
-#include <osl/mutex.hxx>
+#include <mutex>
 #include <memory>
 
 class SdrPage;
@@ -154,7 +154,7 @@ public:
     void Compress(const CacheKey& rKey, const 
std::shared_ptr<BitmapCompressor>& rpCompressor);
 
 private:
-    mutable ::osl::Mutex maMutex;
+    mutable std::mutex maMutex;
 
     std::unique_ptr<CacheBitmapContainer> mpBitmapContainer;
 
@@ -200,7 +200,13 @@ private:
         ADD,
         REMOVE
     };
-    void UpdateCacheSize(const CacheEntry& rKey, CacheOperation eOperation);
+    void UpdateCacheSize(std::unique_lock<std::mutex>& rGuard, const 
CacheEntry& rKey,
+                         CacheOperation eOperation);
+
+    void ReCalculateTotalCacheSize(std::unique_lock<std::mutex>& rGuard);
+
+    void SetBitmap(std::unique_lock<std::mutex>& rGuard, const CacheKey& rKey,
+                   const BitmapEx& rPreview, bool bIsPrecious);
 };
 
 } // end of namespace ::sd::slidesorter::cache

Reply via email to