[gegl] Prevent a data race in gegl_node_get_cache()



commit 981b35046d662e9976910ee0acc31fa68b338ca4
Author: Michael Henning <mikehenning eclipse net>
Date:   Sat May 23 16:29:53 2015 +0200

    Prevent a data race in gegl_node_get_cache()
    
    Filed in bug #676439

 gegl/graph/gegl-node.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index 4ab2103..d3efb0a 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -1876,22 +1876,32 @@ gegl_node_get_cache (GeglNode *node)
       node->cache = NULL;
     }
 
+  if (node->cache)
+    return node->cache;
+
+  g_mutex_lock (&node->mutex);
+
   if (!node->cache)
     {
-      node->cache = g_object_new (GEGL_TYPE_CACHE,
-                                  "format", format,
-                                  NULL);
+      GeglCache *cache;
+
+      cache = g_object_new (GEGL_TYPE_CACHE,
+                            "format", format,
+                            NULL);
 
       gegl_object_set_has_forked (G_OBJECT (node->cache));
 
       gegl_node_get_bounding_box (node);
       gegl_buffer_set_extent (GEGL_BUFFER (node->cache), &node->have_rect);
 
-      g_signal_connect (G_OBJECT (node->cache), "computed",
+      g_signal_connect (G_OBJECT (cache), "computed",
                         (GCallback) gegl_node_computed_event,
                         node);
+      node->cache = cache;
     }
 
+  g_mutex_unlock (&node->mutex);
+
   return node->cache;
 }
 


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