[gegl] buffer: use hot tile under tile_storage lock protection



commit 7b1ec5631abd70f00f3f508e53513c0135ec63ba
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Jul 9 20:36:14 2014 +0200

    buffer: use hot tile under tile_storage lock protection

 gegl/buffer/gegl-buffer-access.c   |   14 +++++++++-----
 gegl/buffer/gegl-buffer.c          |    7 +++++++
 gegl/buffer/gegl-sampler-nearest.c |    5 ++++-
 3 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index d188aff..3106987 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -68,6 +68,8 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
   const GeglRectangle *abyss = &buffer->abyss;
   guchar              *buf   = data;
 
+  
+
   if (y <  abyss->y ||
       x <  abyss->x ||
       y >= abyss->y + abyss->height ||
@@ -113,6 +115,7 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
       }
     }
 
+  if (gegl_config_threads()>1)
   g_rec_mutex_lock (&buffer->tile_storage->mutex);
   {
     gint tile_width  = buffer->tile_width;
@@ -125,7 +128,6 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
     GeglTile *tile = buffer->tile_storage->hot_tile;
     const Babl *fish = NULL;
 
-
     if (!(tile &&
           tile->x == indice_x &&
           tile->y == indice_y))
@@ -160,6 +162,7 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
           }
       }
   }
+  if (gegl_config_threads()>1)
   g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 }
 
@@ -179,6 +182,7 @@ __gegl_buffer_set_pixel (GeglBuffer     *buffer,
       x >= abyss->x + abyss->width)
     return;
 
+  if (gegl_config_threads()>1)
   g_rec_mutex_lock (&buffer->tile_storage->mutex);
   {
     gint tile_width  = buffer->tile_width;
@@ -232,6 +236,7 @@ __gegl_buffer_set_pixel (GeglBuffer     *buffer,
         gegl_tile_unlock (tile);
       }
   }
+  if (gegl_config_threads()>1)
   g_rec_mutex_unlock (&buffer->tile_storage->mutex);
 }
 
@@ -1319,8 +1324,7 @@ gegl_buffer_set (GeglBuffer          *buffer,
   if (format == NULL)
     format = buffer->soft_format;
 
-  if (rect && (rect->width == 1 && rect->height == 1) &&
-    gegl_config()->threads == 1)
+  if (rect && (rect->width == 1 && rect->height == 1))
       _gegl_buffer_set_pixel (buffer, rect->x, rect->y, format, src,
                               GEGL_BUFFER_SET_FLAG_LOCK|GEGL_BUFFER_SET_FLAG_NOTIFY);
   else
@@ -1378,7 +1382,7 @@ _gegl_buffer_get_unlocked (GeglBuffer          *buffer,
 
   if (format == NULL)
     format = buffer->soft_format;
-/*
+
   if (scale == 1.0 &&
       rect &&
       rect->width == 1 &&
@@ -1387,7 +1391,7 @@ _gegl_buffer_get_unlocked (GeglBuffer          *buffer,
       gegl_buffer_get_pixel (buffer, rect->x, rect->y, format, dest_buf, repeat_mode);
       return;
     }
-*/
+
   if (gegl_cl_is_accelerated ())
     {
       gegl_buffer_cl_cache_flush (buffer, rect);
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index f6e78a8..a416500 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -353,11 +353,18 @@ void
 _gegl_buffer_drop_hot_tile (GeglBuffer *buffer)
 {
   GeglTileStorage *storage = buffer->tile_storage;
+
+  if (gegl_config_threads()>1)
+    g_rec_mutex_lock (&storage->mutex);
+
   if (storage->hot_tile)
     {
       gegl_tile_unref (storage->hot_tile);
       storage->hot_tile = NULL;
     }
+
+  if (gegl_config_threads()>1)
+    g_rec_mutex_unlock (&storage->mutex);
 }
 
 static void
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index 5ef59c5..2b4c5fc 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -84,7 +84,6 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
   const GeglRectangle *abyss = &buffer->abyss;
   guchar              *buf   = data;
 
-  gegl_buffer_lock (sampler->buffer);
 
   if (y <  abyss->y ||
       x <  abyss->x ||
@@ -131,6 +130,9 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
       }
     }
 
+  gegl_buffer_lock (sampler->buffer);
+  g_rec_mutex_lock (&buffer->tile_storage->mutex);
+
   {
     gint tile_width  = buffer->tile_width;
     gint tile_height = buffer->tile_height;
@@ -164,6 +166,7 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
         babl_process (sampler->fish, tp, buf, 1);
       }
   }
+  g_rec_mutex_unlock (&buffer->tile_storage->mutex);
   gegl_buffer_unlock (sampler->buffer);
 }
 


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