[gegl] factor away function-call in check for threading



commit 327080a4ad94674a11a10e6d5b63772ceace739b
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Jul 10 16:45:30 2014 +0200

    factor away function-call in check for threading

 gegl/buffer/gegl-buffer-iterator.c              |    2 +-
 gegl/buffer/gegl-buffer.c                       |    2 +-
 gegl/buffer/gegl-sampler-nearest.c              |    2 +-
 gegl/gegl-config.c                              |    6 ++++--
 gegl/gegl-config.h                              |    4 ++--
 gegl/gegl-init.c                                |   17 +++++------------
 gegl/operation/gegl-operation-composer.c        |    4 ++--
 gegl/operation/gegl-operation-composer3.c       |    4 ++--
 gegl/operation/gegl-operation-filter.c          |    4 ++--
 gegl/operation/gegl-operation-point-composer.c  |    6 +++---
 gegl/operation/gegl-operation-point-composer3.c |    6 +++---
 gegl/operation/gegl-operation-point-filter.c    |    6 +++---
 gegl/operation/gegl-operation-source.c          |    4 ++--
 gegl/operation/gegl-operation.c                 |    2 +-
 operations/transform/transform-core.c           |    4 ++--
 15 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index dc9fea4..00e4e53 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -92,7 +92,7 @@ gegl_buffer_iterator_empty_new (void)
   iter->priv->num_buffers = 0;
   iter->priv->state       = GeglIteratorState_Start;
 
-  threaded = gegl_config()->threads > 1;
+  threaded = gegl_config_threads () > 1;
 
   return iter;
 }
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 7c756f4..d3716b6 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -1198,7 +1198,7 @@ gegl_buffer_get_tile (GeglBuffer *buffer,
 
   if (threaded == -1)
   {
-    threaded = gegl_config()->threads > 1;
+    threaded = gegl_config_threads () > 1;
   }
 
   g_assert (source);
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index 4461a83..5ef59c5 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -223,7 +223,7 @@ gegl_sampler_nearest_prepare (GeglSampler* restrict sampler)
     return;
   GEGL_SAMPLER_NEAREST (sampler)->buffer_bpp = babl_format_get_bytes_per_pixel (sampler->buffer->format);
 
-  if (gegl_config()->threads > 1)
+  if (gegl_config_threads () > 1)
     sampler->get = gegl_sampler_nearest_get_threaded;
 
 #if 0 // maybe re-enable; when certain result is correct
diff --git a/gegl/gegl-config.c b/gegl/gegl-config.c
index ac374f9..58a3a90 100644
--- a/gegl/gegl-config.c
+++ b/gegl/gegl-config.c
@@ -48,6 +48,8 @@ enum
   PROP_APPLICATION_LICENSE
 };
 
+gint _gegl_threads = 1; 
+
 static void
 gegl_config_get_property (GObject    *gobject,
                           guint       property_id,
@@ -83,7 +85,7 @@ gegl_config_get_property (GObject    *gobject,
         break;
 
       case PROP_THREADS:
-        g_value_set_int (value, config->threads);
+        g_value_set_int (value, _gegl_threads);
         break;
 
       case PROP_USE_OPENCL:
@@ -135,7 +137,7 @@ gegl_config_set_property (GObject      *gobject,
         config->swap = g_value_dup_string (value);
         break;
       case PROP_THREADS:
-        config->threads = g_value_get_int (value);
+        _gegl_threads = g_value_get_int (value);
         return;
       case PROP_USE_OPENCL:
         config->use_opencl = g_value_get_boolean (value);
diff --git a/gegl/gegl-config.h b/gegl/gegl-config.h
index 6c17e84..a70defa 100644
--- a/gegl/gegl-config.h
+++ b/gegl/gegl-config.h
@@ -41,7 +41,6 @@ struct _GeglConfig
   gdouble  quality;
   gint     tile_width;
   gint     tile_height;
-  gint     threads;
   gboolean use_opencl;
   gint     queue_size;
   gchar   *application_license;
@@ -52,7 +51,8 @@ struct _GeglConfigClass
   GObjectClass parent_class;
 };
 
-gint gegl_config_threads (void);
+extern gint _gegl_threads;
+#define gegl_config_threads()  (_gegl_threads)
 
 #define GEGL_MAX_THREADS 16
 
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 65b6a4f..2afd95a 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -357,13 +357,13 @@ static void gegl_config_parse_env (GeglConfig *config)
 
   if (g_getenv ("GEGL_THREADS"))
     {
-      config->threads = atoi(g_getenv("GEGL_THREADS"));
+      _gegl_threads = atoi(g_getenv("GEGL_THREADS"));
 
-      if (config->threads > GEGL_MAX_THREADS)
+      if (_gegl_threads > GEGL_MAX_THREADS)
         {
           g_warning ("Tried to use %i threads, max is %i",
-                     config->threads, GEGL_MAX_THREADS);
-          config->threads = GEGL_MAX_THREADS;
+                     _gegl_threads, GEGL_MAX_THREADS);
+          _gegl_threads = GEGL_MAX_THREADS;
         }
     }
 
@@ -399,13 +399,6 @@ GeglConfig *gegl_config (void)
   return config;
 }
 
-gint gegl_config_threads (void)
-{
-  if (!config)
-    config = gegl_config ();
-  return config->threads;
-}
-
 static void swap_clean (void)
 {
   const gchar  *swap_dir = gegl_swap_dir ();
@@ -617,7 +610,7 @@ gegl_post_parse_hook (GOptionContext *context,
         config->tile_height = atoi(str+1);
     }
   if (cmd_gegl_threads)
-    config->threads = atoi (cmd_gegl_threads);
+    _gegl_threads = atoi (cmd_gegl_threads);
   if (cmd_gegl_disable_opencl)
     gegl_cl_hard_disable ();
 
diff --git a/gegl/operation/gegl-operation-composer.c b/gegl/operation/gegl-operation-composer.c
index a1a2a5f..1ea6a19 100644
--- a/gegl/operation/gegl-operation-composer.c
+++ b/gegl/operation/gegl-operation-composer.c
@@ -124,7 +124,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -164,7 +164,7 @@ gegl_operation_composer_process (GeglOperation        *operation,
     {
       if (gegl_operation_use_threading (operation, result))
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         gint pending = threads;
diff --git a/gegl/operation/gegl-operation-composer3.c b/gegl/operation/gegl-operation-composer3.c
index 22c6d49..92fe61e 100644
--- a/gegl/operation/gegl-operation-composer3.c
+++ b/gegl/operation/gegl-operation-composer3.c
@@ -135,7 +135,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
   {
-    pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+    pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
         FALSE, NULL);
   }
   return pool;
@@ -186,7 +186,7 @@ gegl_operation_composer3_process (GeglOperation        *operation,
     {
       if (gegl_operation_use_threading (operation, result))
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         gint pending = threads;
diff --git a/gegl/operation/gegl-operation-filter.c b/gegl/operation/gegl-operation-filter.c
index c7e3754..aaaae40 100644
--- a/gegl/operation/gegl-operation-filter.c
+++ b/gegl/operation/gegl-operation-filter.c
@@ -131,7 +131,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -167,7 +167,7 @@ gegl_operation_filter_process (GeglOperation        *operation,
 
   if (gegl_operation_use_threading (operation, result))
   {
-    gint threads = gegl_config ()->threads;
+    gint threads = gegl_config_threads ();
     GThreadPool *pool = thread_pool ();
     ThreadData thread_data[GEGL_MAX_THREADS];
     gint pending = threads;
diff --git a/gegl/operation/gegl-operation-point-composer.c b/gegl/operation/gegl-operation-point-composer.c
index 771537c..643f34a 100644
--- a/gegl/operation/gegl-operation-point-composer.c
+++ b/gegl/operation/gegl-operation-point-composer.c
@@ -89,7 +89,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -218,7 +218,7 @@ gegl_operation_point_composer_process (GeglOperation       *operation,
 
       if (gegl_operation_use_threading (operation, result) && result->height > 1)
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format,
@@ -292,7 +292,7 @@ gegl_operation_point_composer_process (GeglOperation       *operation,
 
         while (gegl_buffer_iterator_next (i))
           {
-            gint threads = gegl_config()->threads;
+            gint threads = gegl_config_threads ();
             gint pending;
             gint bit;
 
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index 1ddc5c7..1c6242e 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -98,7 +98,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -237,7 +237,7 @@ gegl_operation_point_composer3_process (GeglOperation       *operation,
 
       if (gegl_operation_use_threading (operation, result) && result->height > 1)
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format, 
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
@@ -334,7 +334,7 @@ gegl_operation_point_composer3_process (GeglOperation       *operation,
 
         while (gegl_buffer_iterator_next (i))
           {
-            gint threads = gegl_config()->threads;
+            gint threads = gegl_config_threads ();
             gint pending;
             gint bit;
 
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index dad93ac..3d98fd6 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -80,7 +80,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -195,7 +195,7 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 
       if (gegl_operation_use_threading (operation, result) && result->height > 1)
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format, 
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
@@ -242,7 +242,7 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 
         while (gegl_buffer_iterator_next (i))
           {
-            gint threads = gegl_config()->threads;
+            gint threads = gegl_config_threads ();
             gint pending;
             gint bit;
 
diff --git a/gegl/operation/gegl-operation-source.c b/gegl/operation/gegl-operation-source.c
index 7be0333..eb89a8e 100644
--- a/gegl/operation/gegl-operation-source.c
+++ b/gegl/operation/gegl-operation-source.c
@@ -105,7 +105,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads (),
                                  FALSE, NULL);
     }
   return pool;
@@ -133,7 +133,7 @@ gegl_operation_source_process (GeglOperation        *operation,
 
   if (gegl_operation_use_threading (operation, result))
   {
-    gint threads = gegl_config ()->threads;
+    gint threads = gegl_config_threads ();
     GThreadPool *pool = thread_pool ();
     ThreadData thread_data[GEGL_MAX_THREADS];
     gint pending = threads;
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index 03ca7cd..add450a 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -751,7 +751,7 @@ gboolean
 gegl_operation_use_threading (GeglOperation *operation,
                               const GeglRectangle *roi)
 {
-  gint threads = gegl_config ()->threads;
+  gint threads = gegl_config_threads ();
   if (threads == 1)
     return FALSE;
 
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index ea0bf8e..a207c9b 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -731,7 +731,7 @@ static GThreadPool *thread_pool (void)
   static GThreadPool *pool = NULL;
   if (!pool)
     {
-      pool =  g_thread_pool_new (thread_process, NULL, gegl_config()->threads,
+      pool =  g_thread_pool_new (thread_process, NULL, gegl_config_threads(),
                                  FALSE, NULL);
     }
   return pool;
@@ -1268,7 +1268,7 @@ gegl_transform_process (GeglOperation        *operation,
 
       if (gegl_operation_use_threading (operation, result))
       {
-        gint threads = gegl_config ()->threads;
+        gint threads = gegl_config_threads ();
         GThreadPool *pool = thread_pool ();
         ThreadData thread_data[GEGL_MAX_THREADS];
         gint pending = threads;


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