[gegl/threaded-base-classes] tile: lock shuffling



commit 72a360b47ac7f0a603f0dd8f900c00d48a54fa1a
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Jun 26 22:25:48 2014 +0200

    tile: lock shuffling

 gegl/buffer/gegl-tile.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index dfab126..6c5a572 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -56,12 +56,11 @@ void gegl_tile_unref (GeglTile *tile)
    * the in-memory tile is written to disk before we free the memory,
    * otherwise this data will be lost.
    */
-  if (!gegl_tile_is_stored (tile))
-    gegl_tile_store (tile);
+  gegl_tile_store (tile);
 
+  g_mutex_lock (&cowmutex);
   if (tile->data)
     {
-      g_mutex_lock (&cowmutex);
       if (tile->next_shared == tile)
         { /* no clones */
           g_mutex_unlock (&cowmutex);
@@ -81,6 +80,8 @@ void gegl_tile_unref (GeglTile *tile)
           g_mutex_unlock (&cowmutex);
         }
     }
+  else
+    g_mutex_unlock (&cowmutex);
 
   g_slice_free (GeglTile, tile);
 }
@@ -111,6 +112,8 @@ gegl_tile_dup (GeglTile *src)
 {
   GeglTile *tile = gegl_tile_new_bare ();
 
+  g_mutex_lock (&cowmutex);
+
   tile->tile_storage = src->tile_storage;
   tile->data         = src->data;
   tile->size         = src->size;
@@ -119,8 +122,6 @@ gegl_tile_dup (GeglTile *src)
   tile->destroy_notify      = src->destroy_notify;
   tile->destroy_notify_data = src->destroy_notify_data;
 
-  g_mutex_lock (&cowmutex);
-
   tile->next_shared              = src->next_shared;
   src->next_shared               = tile;
   tile->prev_shared              = src;
@@ -266,10 +267,12 @@ gegl_tile_is_stored (GeglTile *tile)
 void
 gegl_tile_void (GeglTile *tile)
 {
+  g_mutex_lock (&tile->tile_storage->mutex);
   gegl_tile_mark_as_stored (tile);
 
   if (tile->z == 0)
     gegl_tile_void_pyramid (tile);
+  g_mutex_unlock (&tile->tile_storage->mutex);
 }
 
 gboolean gegl_tile_store (GeglTile *tile)
@@ -280,6 +283,11 @@ gboolean gegl_tile_store (GeglTile *tile)
   if (tile->tile_storage == NULL)
     return FALSE;
   g_mutex_lock (&tile->tile_storage->mutex);
+  if (gegl_tile_is_stored (tile))
+  {
+    g_mutex_unlock (&tile->tile_storage->mutex);
+    return FALSE;
+  }
   ret = gegl_tile_source_set_tile (GEGL_TILE_SOURCE (tile->tile_storage),
                                     tile->x,
                                     tile->y,


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