[gegl] add gegl_temp_buffer pool



commit 8d43ca3e261d09fa20405354e063da5086604534
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jul 1 00:52:30 2014 +0200

    add gegl_temp_buffer pool
    
    A way to create temporary buffers for babl conversions in threaded point-ops.

 gegl/gegl-init.c                |    4 ++++
 gegl/operation/gegl-operation.c |   27 +++++++++++++++++++++++++++
 gegl/operation/gegl-operation.h |    8 ++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index ff8ac8e..65b6a4f 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -443,6 +443,8 @@ static void swap_clean (void)
     }
 }
 
+void gegl_temp_buffer_free (void);
+
 void
 gegl_exit (void)
 {
@@ -461,6 +463,8 @@ gegl_exit (void)
   gegl_random_cleanup ();
   gegl_cl_cleanup ();
 
+  gegl_temp_buffer_free ();
+
   if (module_db != NULL)
     {
       g_object_unref (module_db);
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index 8bbfb59..03ca7cd 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -769,3 +769,30 @@ gegl_operation_use_threading (GeglOperation *operation,
   return FALSE;
 }
 
+static guchar *gegl_temp_alloc[GEGL_MAX_THREADS * 4]={NULL,};
+static gint    gegl_temp_size[GEGL_MAX_THREADS * 4]={0,};
+
+guchar *gegl_temp_buffer (int no, int size)
+{
+  if (!gegl_temp_alloc[no] || gegl_temp_size[no] < size)
+  {
+    if (gegl_temp_alloc[no])
+      gegl_free (gegl_temp_alloc[no]);
+    gegl_temp_alloc[no] = gegl_malloc (size);
+    gegl_temp_size[no] = size;
+  }
+  return gegl_temp_alloc[no];
+}
+
+void gegl_temp_buffer_free (void);
+void gegl_temp_buffer_free (void)
+{
+  int no;
+  for (no = 0; no < GEGL_MAX_THREADS * 4; no++)
+    if (gegl_temp_alloc[no])
+    {
+      gegl_free (gegl_temp_alloc[no]);
+      gegl_temp_alloc[no] = NULL;
+      gegl_temp_size[no] = 0;
+    }
+}
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index 4b323b4..5fc5deb 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -293,6 +293,14 @@ void     gegl_object_set_has_forked       (GObject *object);
  */
 gboolean  gegl_object_get_has_forked      (GObject *object);
 
+/**
+ * gegl_temp_buffer:
+ *
+ * Returns a singleton scratch buffer for use with multi-threaded processing
+ * dispatch.
+ */
+guchar    *gegl_temp_buffer (int no, int min_size);
+
 G_END_DECLS
 
 /***


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