[gegl] buffer: allow multiple threads to trim the cache concurrently



commit 26583900327bf4cff3c8e9461d918889a103b317
Author: Ell <ell_se yahoo com>
Date:   Sun Dec 30 14:24:29 2018 -0500

    buffer: allow multiple threads to trim the cache concurrently
    
    In the cache tile-handler, allow multiple threads to trim the cache
    concurrently.  This is particularly useful since last commit, as it
    allows all threads waiting on the cache to participate in swap tile
    compression.
    
    Note that each thread can only trim a separate cache tile-handler,
    which means that some threads may trim tiles not belonging to the
    LRU cache.  Hopefully, this wouldn't have a significant impact.

 gegl/buffer/gegl-tile-handler-cache.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index c1f696bd2..85487279d 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -547,6 +547,8 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
 
   target_size -= target_size * ratio;
 
+  g_mutex_unlock (&mutex);
+
   while ((guintptr) g_atomic_pointer_get (&cache_total) > target_size)
     {
       CacheItem *last_writable;
@@ -563,6 +565,8 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
           if (cache)
             g_rec_mutex_unlock (&cache->tile_storage->mutex);
 
+          g_mutex_lock (&mutex);
+
           do
             {
               cache = gegl_tile_handler_cache_find_oldest_cache (cache);
@@ -578,6 +582,8 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
                   */
                  ! g_rec_mutex_trylock (&cache->tile_storage->mutex));
 
+          g_mutex_unlock (&mutex);
+
           if (! cache)
             break;
 
@@ -642,6 +648,8 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
   if (cache)
     g_rec_mutex_unlock (&cache->tile_storage->mutex);
 
+  g_mutex_lock (&mutex);
+
   last_time = g_get_monotonic_time ();
 
   g_mutex_unlock (&mutex);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]