[gegl] buffer: avoid over-trimming cache if already trimmed



commit cc88a234825b035e5e28804f13a71c25778f11d6
Author: Ell <ell_se yahoo com>
Date:   Mon Dec 10 10:17:09 2018 -0500

    buffer: avoid over-trimming cache if already trimmed
    
    In gegl_tile_handler_cache_trim(), check if the cache needs
    trimming before deciding how much to over-trim, and bail if no
    trimming is needed in the first place.  This is necessary, since
    two threads may try to trim the cache concurrently, in which case
    one thread will block until the other thread finishes trimming.  At
    this point, we want the other thread to avoid trimming, instead of
    increasing the over-trim ratio, and trimming extra tiles.

 gegl/buffer/gegl-tile-handler-cache.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index 5b3719f8f..4c67685ea 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -529,6 +529,15 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
 
   g_mutex_lock (&mutex);
 
+  target_size = gegl_buffer_config ()->tile_cache_size;
+
+  if ((guintptr) g_atomic_pointer_get (&cache_total) <= target_size)
+    {
+      g_mutex_unlock (&mutex);
+
+      return TRUE;
+    }
+
   time = g_get_monotonic_time ();
 
   if (time - last_time < GEGL_CACHE_TRIM_INTERVAL)
@@ -541,7 +550,6 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
       ratio = GEGL_CACHE_TRIM_RATIO_MIN;
     }
 
-  target_size  = gegl_buffer_config ()->tile_cache_size;
   target_size -= target_size * ratio;
 
   while ((guintptr) g_atomic_pointer_get (&cache_total) > target_size)


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