[gegl/threaded-base-classes: 19/22] refactoring point process3 towards threads



commit ef0dcc874dfb9fb5d8784cd53227829f07e32fa8
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Jun 28 03:30:13 2014 +0200

    refactoring point process3 towards threads

 gegl/operation/gegl-operation-point-composer3.c |   82 +++++++++++++----------
 1 files changed, 46 insertions(+), 36 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index 08d4f1d..b8c9add 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -27,6 +27,42 @@
 #include "gegl-config.h"
 #include <string.h>
 
+typedef struct ThreadData
+{
+  GeglOperationPointComposer3Class *klass;
+  GeglOperation               *operation;
+  guchar                      *input;
+  guchar                      *aux;
+  guchar                      *aux2;
+  guchar                      *output;
+  gint                        *pending;
+  gint                         level;
+  gboolean                     success;
+  GeglRectangle                roi;
+} ThreadData;
+
+static void thread_process (gpointer thread_data, gpointer unused)
+{
+  ThreadData *data = thread_data;
+  if (!data->klass->process (data->operation,
+                       data->input, data->aux, data->aux2, 
+                       data->output, data->roi.width * data->roi.height, 
+                       &data->roi, data->level))
+    data->success = FALSE;
+  g_atomic_int_add (data->pending, -1);
+}
+
+static GThreadPool *thread_pool (void)
+{
+  static GThreadPool *pool = NULL;
+  if (!pool)
+    {
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+                                 FALSE, NULL);
+    }
+  return pool;
+}
+
 static gboolean
 gegl_operation_composer3_process (GeglOperation        *operation,
                                   GeglOperationContext *context,
@@ -153,46 +189,20 @@ gegl_operation_point_composer3_process (GeglOperation       *operation,
   if ((result->width > 0) && (result->height > 0))
     {
       GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format, 
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
-      gint read  = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
+      gint foo = 0, bar = 0, read = 0;
 
+      if (input)
+        read = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
       if (aux)
+        foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
+      if (aux2)
+        bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
+
+      while (gegl_buffer_iterator_next (i))
         {
-          gint foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
-          if (aux2)
-            {
-              gint bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
-
-              while (gegl_buffer_iterator_next (i))
-                {
-                   point_composer3_class->process (operation, i->data[read], i->data[foo], i->data[bar], 
i->data[0], i->length, &(i->roi[0]), level);
-                }
-            }
-          else
-            {
-              while (gegl_buffer_iterator_next (i))
-                {
-                   point_composer3_class->process (operation, i->data[read], i->data[foo], NULL, i->data[0], 
i->length, &(i->roi[0]), level);
-                }
-            }
-        }
-      else
-        {
-          if (aux2)
-            {
-              gint bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, 
GEGL_ABYSS_NONE);
-              while (gegl_buffer_iterator_next (i))
-                {
-                   point_composer3_class->process (operation, i->data[read], NULL, i->data[bar], i->data[0], 
i->length, &(i->roi[0]), level);
-                }
-            }
-          else
-            {
-              while (gegl_buffer_iterator_next (i))
-                {
-                   point_composer3_class->process (operation, i->data[read], NULL, NULL, i->data[0], 
i->length, &(i->roi[0]), level);
-                }
-            }
+          point_composer3_class->process (operation, i->data[read], i->data[foo], i->data[bar], i->data[0], 
i->length, &(i->roi[0]), level);
         }
+
       return TRUE;
     }
   return TRUE;


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