[gegl] gegl-buffer: always do locking



commit c8a0b9eff07c8d9122f55f7b7527d51788ae4575
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Sep 19 15:56:23 2018 +0200

    gegl-buffer: always do locking
    
    This reduces the throughpput of gegl buffer accessors and more slightly in
    the single-threaded case, which is now becoming rare - at least when GEGL
    is operated through GIMP.
    
    Relying less on this dynamically changing parameter from gegl_config()
    will also make it easier to split GeglBuffer out in its own project.

 gegl/buffer/gegl-buffer-access.c       | 73 +++++++++++-----------------------
 gegl/buffer/gegl-buffer-iterator.c     |  5 ---
 gegl/buffer/gegl-buffer-iterator2.c    |  5 ---
 gegl/buffer/gegl-buffer.c              | 54 ++++++++-----------------
 gegl/buffer/gegl-sampler-nearest.c     |  7 +---
 gegl/buffer/gegl-sampler.c             |  1 -
 gegl/buffer/gegl-tile-backend-buffer.c | 14 ++-----
 gegl/buffer/gegl-tile-handler-cache.c  | 11 ++---
 gegl/buffer/gegl-tile-handler.c        |  7 +---
 gegl/buffer/gegl-tile-storage.c        | 55 ++++++-------------------
 gegl/buffer/gegl-tile.c                | 23 ++++-------
 11 files changed, 74 insertions(+), 181 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 4f7811480..e5eeb0171 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -39,7 +39,6 @@
 #include "gegl-tile-backend.h"
 #include "gegl-buffer-iterator.h"
 #include "gegl-buffer-iterator-private.h"
-#include "gegl-config.h"
 #include "gegl-types-internal.h"
 
 static void gegl_buffer_iterate_read_fringed (GeglBuffer          *buffer,
@@ -130,8 +129,7 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
           tile->x == indice_x &&
           tile->y == indice_y))
       {
-        if (gegl_config_threads()>1)
-          g_rec_mutex_lock (&buffer->tile_storage->mutex);
+        g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
         if (tile)
           gegl_tile_unref (tile);
@@ -140,8 +138,7 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
                                           indice_x, indice_y,
                                           0);
 
-        if (gegl_config_threads()>1)
-          g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+        g_rec_mutex_unlock (&buffer->tile_storage->mutex);
       }
 
     if (tile)
@@ -217,8 +214,7 @@ __gegl_buffer_set_pixel (GeglBuffer     *buffer,
           tile->x == indice_x &&
           tile->y == indice_y))
       {
-        if (gegl_config_threads()>1)
-          g_rec_mutex_lock (&buffer->tile_storage->mutex);
+        g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
         if (tile)
           gegl_tile_unref (tile);
@@ -227,8 +223,7 @@ __gegl_buffer_set_pixel (GeglBuffer     *buffer,
                                           indice_x, indice_y,
                                           0);
 
-        if (gegl_config_threads()>1)
-          g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+        g_rec_mutex_unlock (&buffer->tile_storage->mutex);
       }
 
     if (tile)
@@ -319,8 +314,7 @@ gegl_buffer_flush (GeglBuffer *buffer)
   g_return_if_fail (GEGL_IS_BUFFER (buffer));
   backend = gegl_buffer_backend (buffer);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_lock (&buffer->tile_storage->mutex);
+  g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
   _gegl_buffer_drop_hot_tile (buffer);
 
@@ -330,8 +324,7 @@ gegl_buffer_flush (GeglBuffer *buffer)
   gegl_tile_source_command (GEGL_TILE_SOURCE (buffer),
                             GEGL_TILE_FLUSH, 0,0,0,NULL);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+  g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 }
 
 void
@@ -984,22 +977,12 @@ gegl_buffer_iterate_read_simple (GeglBuffer          *buffer,
           else
             pixels = tile_width - offsetx;
 
-          if (gegl_config_threads()>1)
-          {
-             g_rec_mutex_lock (&buffer->tile_storage->mutex);
-             tile = gegl_tile_source_get_tile ((GeglTileSource *) (buffer),
-                                            gegl_tile_indice (tiledx, tile_width),
-                                            gegl_tile_indice (tiledy, tile_height),
-                                            level);
-            g_rec_mutex_unlock (&buffer->tile_storage->mutex);
-          }
-          else
-          {
-             tile = gegl_tile_source_get_tile ((GeglTileSource *) (buffer),
-                                            gegl_tile_indice (tiledx, tile_width),
-                                            gegl_tile_indice (tiledy, tile_height),
-                                            level);
-          }
+          g_rec_mutex_lock (&buffer->tile_storage->mutex);
+          tile = gegl_tile_source_get_tile ((GeglTileSource *) (buffer),
+                                          gegl_tile_indice (tiledx, tile_width),
+                                          gegl_tile_indice (tiledy, tile_height),
+                                          level);
+          g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 
           if (!tile)
             {
@@ -2431,18 +2414,15 @@ gegl_buffer_copy (GeglBuffer          *src,
              */
             fast_copy = (src->tile_storage->n_user_handlers == 0);
 
-            if (gegl_config_threads()>1)
+            if (src < dst)
               {
-                if (src < dst)
-                  {
-                    g_rec_mutex_lock (&src->tile_storage->mutex);
-                    g_rec_mutex_lock (&dst->tile_storage->mutex);
-                  }
-                else
-                  {
-                    g_rec_mutex_lock (&dst->tile_storage->mutex);
-                    g_rec_mutex_lock (&src->tile_storage->mutex);
-                  }
+                g_rec_mutex_lock (&src->tile_storage->mutex);
+                g_rec_mutex_lock (&dst->tile_storage->mutex);
+              }
+            else
+              {
+                g_rec_mutex_lock (&dst->tile_storage->mutex);
+                g_rec_mutex_lock (&src->tile_storage->mutex);
               }
 
             for (dst_y = cow_rect.y + dst->shift_y; dst_y < cow_rect.y + dst->shift_y + cow_rect.height; 
dst_y += tile_height)
@@ -2481,11 +2461,8 @@ gegl_buffer_copy (GeglBuffer          *src,
                   }
               }
 
-            if (gegl_config_threads()>1)
-              {
-                g_rec_mutex_unlock (&src->tile_storage->mutex);
-                g_rec_mutex_unlock (&dst->tile_storage->mutex);
-              }
+            g_rec_mutex_unlock (&src->tile_storage->mutex);
+            g_rec_mutex_unlock (&dst->tile_storage->mutex);
           }
 
           top = *dst_rect;
@@ -2631,8 +2608,7 @@ gegl_buffer_clear (GeglBuffer          *dst,
 
             gint dst_x, dst_y;
 
-            if (gegl_config_threads()>1)
-              g_rec_mutex_lock (&dst->tile_storage->mutex);
+            g_rec_mutex_lock (&dst->tile_storage->mutex);
 
             for (dst_y = cow_rect.y + dst->shift_y; dst_y < cow_rect.y + dst->shift_y + cow_rect.height; 
dst_y += tile_height)
             for (dst_x = cow_rect.x + dst->shift_x; dst_x < cow_rect.x + dst->shift_x + cow_rect.width; 
dst_x += tile_width)
@@ -2645,8 +2621,7 @@ gegl_buffer_clear (GeglBuffer          *dst,
                 gegl_tile_source_void ((GeglTileSource*)dst, dtx, dty, 0);
               }
 
-            if (gegl_config_threads()>1)
-              g_rec_mutex_unlock (&dst->tile_storage->mutex);
+            g_rec_mutex_unlock (&dst->tile_storage->mutex);
           }
 
           top = *dst_rect;
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index ceb60daab..22b6af83c 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -30,7 +30,6 @@
 #include "gegl-buffer-iterator.h"
 #include "gegl-buffer-iterator-private.h"
 #include "gegl-buffer-private.h"
-#include "gegl-config.h"
 
 typedef enum {
   GeglIteratorState_Start,
@@ -78,8 +77,6 @@ struct _GeglBufferIteratorPriv
   SubIterState      sub_iter[GEGL_BUFFER_MAX_ITERATORS];
 };
 
-static gboolean threaded = TRUE;
-
 static inline GeglBufferIterator *
 _gegl_buffer_iterator_empty_new (void)
 {
@@ -89,8 +86,6 @@ _gegl_buffer_iterator_empty_new (void)
   iter->priv->num_buffers = 0;
   iter->priv->state       = GeglIteratorState_Start;
 
-  threaded = gegl_config_threads () > 1;
-
   return iter;
 }
 
diff --git a/gegl/buffer/gegl-buffer-iterator2.c b/gegl/buffer/gegl-buffer-iterator2.c
index 53795969c..89cf7ff54 100644
--- a/gegl/buffer/gegl-buffer-iterator2.c
+++ b/gegl/buffer/gegl-buffer-iterator2.c
@@ -32,7 +32,6 @@
 #include "gegl-buffer-iterator-private.h"
 #include "gegl-buffer-private.h"
 #include "gegl-buffer-cl-cache.h"
-#include "gegl-config.h"
 
 typedef enum {
   GeglIteratorState_Start,
@@ -84,8 +83,6 @@ struct _GeglBufferIterator2Priv
                                         */
 };
 
-static gboolean threaded = TRUE;
-
 static inline gint *
 get_access_order (GeglBufferIterator2 *iter)
 {
@@ -110,8 +107,6 @@ _gegl_buffer_iterator2_empty_new (gint max_slots)
   iter->priv->num_buffers = 0;
   iter->priv->state       = GeglIteratorState_Start;
 
-  threaded = gegl_config_threads () > 1;
-
   return iter;
 }
 
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 2c73023d3..c13d28361 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -38,6 +38,7 @@
 
 #include "gegl-buffer-types.h"
 #include "gegl-buffer.h"
+#include "gegl-config.h" // XXX should be removed
 #include "gegl-buffer-private.h"
 #include "gegl-debug.h"
 #include "gegl-tile-storage.h"
@@ -46,7 +47,6 @@
 #include "gegl-tile-backend-ram.h"
 
 //#include "opencl/gegl-cl.h"
-#include "gegl-config.h" /* XXX: include of file outside buffer dir */
 
 #include "gegl-types-internal.h"
 
@@ -331,8 +331,7 @@ gegl_buffer_leaks (void)
     {
       GList *leaked_buffer = NULL;
 
-      if (gegl_config_threads()>1)
-        g_mutex_lock (&allocated_buffers_mutex);
+      g_mutex_lock (&allocated_buffers_mutex);
 
       for (leaked_buffer = allocated_buffers_list;
            leaked_buffer != NULL;
@@ -351,8 +350,7 @@ gegl_buffer_leaks (void)
       g_list_free (allocated_buffers_list);
       allocated_buffers_list = NULL;
 
-      if (gegl_config_threads()>1)
-        g_mutex_unlock (&allocated_buffers_mutex);
+      g_mutex_unlock (&allocated_buffers_mutex);
     }
 #endif
 
@@ -405,11 +403,9 @@ gegl_buffer_finalize (GObject *object)
 #ifdef GEGL_ENABLE_DEBUG
   if (DEBUG_ALLOCATIONS)
     {
-      if (gegl_config_threads()>1)
-        g_mutex_lock (&allocated_buffers_mutex);
+      g_mutex_lock (&allocated_buffers_mutex);
       allocated_buffers_list = g_list_remove (allocated_buffers_list, object);
-      if (gegl_config_threads()>1)
-        g_mutex_unlock (&allocated_buffers_mutex);
+      g_mutex_unlock (&allocated_buffers_mutex);
       g_free (GEGL_BUFFER (object)->alloc_stack_trace);
     }
 #endif
@@ -929,11 +925,9 @@ gegl_buffer_init (GeglBuffer *buffer)
   if (DEBUG_ALLOCATIONS)
     {
       gegl_buffer_set_alloc_stack (buffer);
-      if (gegl_config_threads()>1)
-        g_mutex_lock (&allocated_buffers_mutex);
+      g_mutex_lock (&allocated_buffers_mutex);
       allocated_buffers_list = g_list_prepend (allocated_buffers_list, buffer);
-      if (gegl_config_threads()>1)
-        g_mutex_unlock (&allocated_buffers_mutex);
+      g_mutex_unlock (&allocated_buffers_mutex);
     }
 #endif
 }
@@ -1127,18 +1121,14 @@ gegl_buffer_try_lock (GeglBuffer *buffer)
   {
     GeglTileBackend *backend = gegl_buffer_backend (buffer);
 
-    gboolean threaded = gegl_config_threads ()>1;
-
-    if (threaded)
-      g_rec_mutex_lock (&buffer->tile_storage->mutex);
+    g_rec_mutex_lock (&buffer->tile_storage->mutex);
     if (buffer->lock_count > 0)
       buffer->lock_count++;
     else if (gegl_tile_backend_file_try_lock (GEGL_TILE_BACKEND_FILE (backend)))
       buffer->lock_count++;
     else
       ret = FALSE;
-    if (threaded)
-      g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+    g_rec_mutex_unlock (&buffer->tile_storage->mutex);
   }
 
   return ret;
@@ -1163,11 +1153,9 @@ gegl_buffer_unlock (GeglBuffer *buffer)
 
   if (gegl_buffer_is_shared (buffer))
   {
-    gboolean threaded = gegl_config_threads ()>1;
     GeglTileBackend *backend = gegl_buffer_backend (buffer);
 
-    if (threaded)
-      g_rec_mutex_lock (&buffer->tile_storage->mutex);
+    g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
     buffer->lock_count--;
     g_assert (buffer->lock_count >= 0);
@@ -1175,8 +1163,7 @@ gegl_buffer_unlock (GeglBuffer *buffer)
     if (buffer->lock_count == 0)
       ret = gegl_tile_backend_file_unlock (GEGL_TILE_BACKEND_FILE (backend));
 
-    if (threaded)
-      g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+    g_rec_mutex_unlock (&buffer->tile_storage->mutex);
   }
 
   return ret;
@@ -1219,23 +1206,16 @@ gegl_buffer_get_tile (GeglBuffer *buffer,
   GeglTile *tile;
 
   g_assert (source);
-
-  if (gegl_config_threads () > 1)
   {
-    GeglTileStorage *tile_storage = buffer->tile_storage;
-    g_assert (tile_storage);
+  GeglTileStorage *tile_storage = buffer->tile_storage;
+  g_assert (tile_storage);
 
-    g_rec_mutex_lock (&tile_storage->mutex);
+  g_rec_mutex_lock (&tile_storage->mutex);
 
-    tile = gegl_tile_source_command (source, GEGL_TILE_GET,
-                                     x, y, z, NULL);
+  tile = gegl_tile_source_command (source, GEGL_TILE_GET,
+                                   x, y, z, NULL);
 
-    g_rec_mutex_unlock (&tile_storage->mutex);
-  }
-  else
-  {
-    return gegl_tile_source_command (source, GEGL_TILE_GET,
-                                     x, y, z, NULL);
+  g_rec_mutex_unlock (&tile_storage->mutex);
   }
 
   return tile;
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index 1686558b6..6444fe990 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -26,7 +26,6 @@
 #include "gegl-buffer-private.h"
 #include "gegl-tile-storage.h"
 #include "gegl-tile-backend.h"
-#include "gegl-config.h"
 #include "gegl-sampler-nearest.h"
 
 enum
@@ -165,8 +164,7 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
           tile->x == indice_x &&
           tile->y == indice_y))
       {
-        if (gegl_config_threads()>1)
-          g_rec_mutex_lock (&buffer->tile_storage->mutex);
+        g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
         if (tile)
           {
@@ -182,8 +180,7 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
 
         gegl_tile_read_lock (tile);
 
-        if (gegl_config_threads()>1)
-          g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+        g_rec_mutex_unlock (&buffer->tile_storage->mutex);
       }
 
     if (tile)
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 2064b46e6..c6bb32101 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -36,7 +36,6 @@
 #include "gegl-sampler-lohalo.h"
 #include "gegl-types-internal.h"
 
-#include "gegl-config.h"
 
 enum
 {
diff --git a/gegl/buffer/gegl-tile-backend-buffer.c b/gegl/buffer/gegl-tile-backend-buffer.c
index bc8a25b39..2711b4cb5 100644
--- a/gegl/buffer/gegl-tile-backend-buffer.c
+++ b/gegl/buffer/gegl-tile-backend-buffer.c
@@ -22,8 +22,6 @@
 
 #include "gegl-buffer-types.h"
 
-#include "gegl-config.h"
-
 #include "gegl-buffer-backend.h"
 #include "gegl-buffer-private.h"
 #include "gegl-tile-backend.h"
@@ -259,13 +257,11 @@ gegl_tile_backend_buffer_set_tile (GeglTileBackendBuffer *tile_backend_buffer,
 
   dest_tile = gegl_tile_dup (tile);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_lock (&buffer->tile_storage->mutex);
+  g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
   gegl_tile_handler_cache_insert (cache, dest_tile, x, y, z);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+  g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 
   gegl_tile_unref (dest_tile);
 
@@ -285,13 +281,11 @@ gegl_tile_backend_buffer_forward_command (GeglTileBackendBuffer *tile_backend_bu
   GeglTileSource *source = GEGL_TILE_SOURCE (buffer);
   gpointer        result;
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_lock (&buffer->tile_storage->mutex);
+  g_rec_mutex_lock (&buffer->tile_storage->mutex);
 
   result = gegl_tile_source_command (source, command, x, y, z, data);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_unlock (&buffer->tile_storage->mutex);
+  g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 
   if (emit_changed_signal)
     gegl_tile_backend_buffer_emit_changed_signal (tile_backend_buffer, x, y, z);
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index 4b5df4aba..97fbad15a 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -406,8 +406,7 @@ gegl_tile_handler_cache_wash (GeglTileHandlerCache *cache)
       if (cache == NULL)
         break;
 
-      if (gegl_config_threads()>1 &&
-          ! g_rec_mutex_trylock (&cache->tile_storage->mutex))
+      if (! g_rec_mutex_trylock (&cache->tile_storage->mutex))
         {
           continue;
         }
@@ -432,8 +431,7 @@ gegl_tile_handler_cache_wash (GeglTileHandlerCache *cache)
           size += tile->size;
         }
 
-      if (gegl_config_threads()>1)
-        g_rec_mutex_unlock (&cache->tile_storage->mutex);
+      g_rec_mutex_unlock (&cache->tile_storage->mutex);
     }
 
   g_mutex_unlock (&mutex);
@@ -536,7 +534,7 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
 
       if (! link)
         {
-          if (cache && gegl_config_threads()>1)
+          if (cache)
             g_rec_mutex_unlock (&cache->tile_storage->mutex);
 
           do
@@ -552,7 +550,6 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
                   * thread.  try locking the cache's storage mutex here, and
                   * skip the cache if it fails.
                   */
-                 gegl_config_threads()>1 &&
                  ! g_rec_mutex_trylock (&cache->tile_storage->mutex));
 
           if (! cache)
@@ -605,7 +602,7 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
       link = prev_link;
     }
 
-  if (cache && gegl_config_threads()>1)
+  if (cache)
     g_rec_mutex_unlock (&cache->tile_storage->mutex);
 
   g_mutex_unlock (&mutex);
diff --git a/gegl/buffer/gegl-tile-handler.c b/gegl/buffer/gegl-tile-handler.c
index e714ad3fe..2c09ec60a 100644
--- a/gegl/buffer/gegl-tile-handler.c
+++ b/gegl/buffer/gegl-tile-handler.c
@@ -28,7 +28,6 @@
 #include "gegl-tile-handler-private.h"
 #include "gegl-tile-storage.h"
 #include "gegl-buffer-private.h"
-#include "gegl-config.h"
 
 struct _GeglTileHandlerPrivate
 {
@@ -251,8 +250,7 @@ gegl_tile_handler_damage_rect (GeglTileHandler     *handler,
 
   source = GEGL_TILE_SOURCE (handler);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_lock (&handler->priv->tile_storage->mutex);
+  g_rec_mutex_lock (&handler->priv->tile_storage->mutex);
 
   tile_width  = handler->priv->tile_storage->tile_width;
   tile_height = handler->priv->tile_storage->tile_height;
@@ -340,6 +338,5 @@ gegl_tile_handler_damage_rect (GeglTileHandler     *handler,
         }
     }
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_unlock (&handler->priv->tile_storage->mutex);
+  g_rec_mutex_unlock (&handler->priv->tile_storage->mutex);
 }
diff --git a/gegl/buffer/gegl-tile-storage.c b/gegl/buffer/gegl-tile-storage.c
index bd50daa0f..6ec87c661 100644
--- a/gegl/buffer/gegl-tile-storage.c
+++ b/gegl/buffer/gegl-tile-storage.c
@@ -26,7 +26,6 @@
 #include "gegl-tile-handler-empty.h"
 #include "gegl-tile-handler-zoom.h"
 #include "gegl-tile-handler-private.h"
-#include "gegl-config.h"
 
 
 G_DEFINE_TYPE (GeglTileStorage, gegl_tile_storage, GEGL_TYPE_TILE_HANDLER_CHAIN)
@@ -129,21 +128,13 @@ gegl_tile_storage_steal_hot_tile (GeglTileStorage *tile_storage)
 {
   GeglTile *tile;
 
-  if (gegl_config_threads()>1)
-    {
-      tile = g_atomic_pointer_get (&tile_storage->hot_tile);
-
-      if (tile &&
-          ! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
-                                                   tile, NULL))
-        {
-          tile = NULL;
-        }
-    }
-  else
+  tile = g_atomic_pointer_get (&tile_storage->hot_tile);
+
+  if (tile &&
+      ! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
+                                               tile, NULL))
     {
-      tile                   = tile_storage->hot_tile;
-      tile_storage->hot_tile = NULL;
+      tile = NULL;
     }
 
   return tile;
@@ -153,21 +144,11 @@ GeglTile *
 gegl_tile_storage_try_steal_hot_tile (GeglTileStorage *tile_storage,
                                       GeglTile        *tile)
 {
-  if (gegl_config_threads()>1)
+  if (tile &&
+      ! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
+                                               tile, NULL))
     {
-      if (tile &&
-          ! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
-                                                   tile, NULL))
-        {
-          tile = NULL;
-        }
-    }
-  else
-    {
-      if (tile_storage->hot_tile == tile)
-        tile_storage->hot_tile = NULL;
-      else
-        tile                   = NULL;
+      tile = NULL;
     }
 
   return tile;
@@ -177,20 +158,10 @@ void
 gegl_tile_storage_take_hot_tile (GeglTileStorage *tile_storage,
                                  GeglTile        *tile)
 {
-  if (gegl_config_threads()>1)
-    {
-      if (! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
-                                                   NULL, tile))
-        {
-          gegl_tile_unref (tile);
-        }
-    }
-  else
+  if (! g_atomic_pointer_compare_and_exchange (&tile_storage->hot_tile,
+                                               NULL, tile))
     {
-      if (! tile_storage->hot_tile)
-        tile_storage->hot_tile = tile;
-      else
-        gegl_tile_unref (tile);
+      gegl_tile_unref (tile);
     }
 }
 
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index 0694ee801..fd88e4eb6 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -29,7 +29,6 @@
 #include "gegl-tile.h"
 #include "gegl-buffer-private.h"
 #include "gegl-tile-storage.h"
-#include "gegl-config.h"
 
 /* the offset at which the tile data begins, when it shares the same buffer as
  * n_clones.  use 16 bytes, which is the alignment we use for gegl_malloc(), so
@@ -341,8 +340,7 @@ gegl_tile_void_pyramid (GeglTile *tile,
       tile->tile_storage->seen_zoom &&
       tile->z == 0) /* we only accepting voiding the base level */
     {
-      if (gegl_config_threads()>1)
-        g_rec_mutex_lock (&tile->tile_storage->mutex);
+      g_rec_mutex_lock (&tile->tile_storage->mutex);
 
       _gegl_tile_void_pyramid (GEGL_TILE_SOURCE (tile->tile_storage),
                                tile->x,
@@ -350,8 +348,7 @@ gegl_tile_void_pyramid (GeglTile *tile,
                                tile->z,
                                damage);
 
-      if (gegl_config_threads()>1)
-        g_rec_mutex_unlock (&tile->tile_storage->mutex);
+      g_rec_mutex_unlock (&tile->tile_storage->mutex);
 
       return;
     }
@@ -469,15 +466,12 @@ gboolean gegl_tile_store (GeglTile *tile)
   if (tile->tile_storage == NULL || tile->damage)
     return FALSE;
 
-  if (gegl_config_threads()>1)
-    {
-      g_rec_mutex_lock (&tile->tile_storage->mutex);
+  g_rec_mutex_lock (&tile->tile_storage->mutex);
 
-      if (gegl_tile_is_stored (tile))
-        {
-          g_rec_mutex_unlock (&tile->tile_storage->mutex);
-          return FALSE;
-        }
+  if (gegl_tile_is_stored (tile))
+    {
+      g_rec_mutex_unlock (&tile->tile_storage->mutex);
+      return FALSE;
     }
 
   ret = gegl_tile_source_set_tile (GEGL_TILE_SOURCE (tile->tile_storage),
@@ -486,8 +480,7 @@ gboolean gegl_tile_store (GeglTile *tile)
                                     tile->z,
                                     tile);
 
-  if (gegl_config_threads()>1)
-    g_rec_mutex_unlock (&tile->tile_storage->mutex);
+  g_rec_mutex_unlock (&tile->tile_storage->mutex);
 
   return ret;
 }


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