[gegl] tile-handler-cache: make flush and wash thread safe



commit 41d4ed8d332c88480fa2917e0e464be966840dc0
Author: Ell <ell_se yahoo com>
Date:   Fri Jul 21 10:56:19 2017 -0400

    tile-handler-cache: make flush and wash thread safe

 gegl/buffer/gegl-tile-handler-cache.c |   44 ++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index b59d0a1..40bfd80 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -219,24 +219,26 @@ gegl_tile_handler_cache_command (GeglTileSource  *tile_store,
     {
       case GEGL_TILE_FLUSH:
         {
-          GList     *link;
-
           if (gegl_cl_is_accelerated ())
             gegl_buffer_cl_cache_flush2 (cache, NULL);
 
           if (cache->count)
             {
-              for (link = g_queue_peek_head_link (cache_queue); link; link = link->next)
+              CacheItem      *item;
+              GHashTableIter  iter;
+              gpointer        key, value;
+
+              g_mutex_lock (&mutex);
+
+              g_hash_table_iter_init (&iter, cache->items);
+              while (g_hash_table_iter_next (&iter, &key, &value))
                 {
-                  CacheItem *item = LINK_GET_ITEM (link);
-                  GeglTile  *tile = item->tile;
-
-                  if (tile != NULL &&
-                      item->handler == cache)
-                    {
-                      gegl_tile_store (tile);
-                    }
+                  item = (CacheItem *) value;
+                  if (item->tile)
+                    gegl_tile_store (item->tile);
                 }
+
+              g_mutex_unlock (&mutex);
             }
         }
         break;
@@ -293,20 +295,34 @@ gegl_tile_handler_cache_wash (GeglTileHandlerCache *cache)
   gint       wash_tiles = cache_wash_percentage * length / 100;
   GList     *link;
 
-  for (link = g_queue_peek_head_link (cache_queue); link; link = link->next)
+  g_mutex_lock (&mutex);
+
+  for (link = g_queue_peek_tail_link (cache_queue);
+       link && count < wash_tiles;
+       link = link->prev, count++)
     {
       CacheItem *item = LINK_GET_ITEM (link);
       GeglTile  *tile = item->tile;
 
-      count++;
       if (!gegl_tile_is_stored (tile))
-        if (count > length - wash_tiles)
+        {
           last_dirty = tile;
+          if (last_dirty->tile_storage)
+            g_object_ref (last_dirty->tile_storage);
+          gegl_tile_ref (last_dirty);
+
+          break;
+        }
     }
 
+  g_mutex_unlock (&mutex);
+
   if (last_dirty != NULL)
     {
       gegl_tile_store (last_dirty);
+      gegl_tile_unref (last_dirty);
+      if (last_dirty->tile_storage)
+        g_object_unref (last_dirty->tile_storage);
       return TRUE;
     }
   return FALSE;


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