[gegl] buffer: add extra locks
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: add extra locks
- Date: Fri, 17 Dec 2010 15:40:39 +0000 (UTC)
commit c7df9d46b5702934a3dcb7e3fd06cd762423c87c
Author: �yvind Kolås <pippin gimp org>
Date: Fri Dec 17 03:08:58 2010 +0000
buffer: add extra locks
configure.ac | 2 +-
gegl/buffer/gegl-buffer-linear.c | 3 +++
gegl/buffer/gegl-buffer.c | 12 ++++++++++--
gegl/buffer/gegl-cache.c | 10 ++++++++++
gegl/buffer/gegl-cache.h | 1 +
perf/tests/comp.c | 2 +-
6 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5233c35..f0f9c72 100644
--- a/configure.ac
+++ b/configure.ac
@@ -357,7 +357,7 @@ if test "x$enable_mmx" = "xyes"; then
AC_MSG_RESULT(yes)
if test "x$enable_sse" = "xyes"; then
- AS_COMPILER_FLAG([-msse], [SSE_EXTRA_CFLAGS="-msse -msse2 -ftree-vectorize -ffast-math -ftree-vectorizer-verbose=3"])
+ AS_COMPILER_FLAG([-msse], [SSE_EXTRA_CFLAGS="-msse -ftree-vectorize -ffast-math"])
AC_MSG_CHECKING(whether we can compile SSE code)
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index fbd2cfc..14f4cee 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -236,7 +236,10 @@ gegl_buffer_linear_close (GeglBuffer *buffer,
*/
}
+ g_mutex_unlock (buffer->tile_storage->mutex);
+ /* XXX: potential race */
gegl_buffer_set (buffer, &info->extent, info->format, info->buf, 0);
+ g_mutex_lock (buffer->tile_storage->mutex);
break;
}
else
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index f249077..89baa16 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -1177,9 +1177,11 @@ gboolean gegl_buffer_try_lock (GeglBuffer *buffer)
{
gboolean ret;
GeglTileBackend *backend = gegl_buffer_backend (buffer);
+ g_mutex_lock (buffer->tile_storage->mutex);
if (buffer->lock_count>0)
{
buffer->lock_count++;
+ g_mutex_unlock (buffer->tile_storage->mutex);
return TRUE;
}
if (gegl_buffer_is_shared(buffer))
@@ -1188,6 +1190,7 @@ gboolean gegl_buffer_try_lock (GeglBuffer *buffer)
ret = TRUE;
if (ret)
buffer->lock_count++;
+ g_mutex_unlock (buffer->tile_storage->mutex);
return TRUE;
}
@@ -1204,11 +1207,16 @@ gboolean gegl_buffer_lock (GeglBuffer *buffer)
gboolean gegl_buffer_unlock (GeglBuffer *buffer)
{
+ gboolean ret = TRUE;
GeglTileBackend *backend = gegl_buffer_backend (buffer);
+ g_mutex_lock (buffer->tile_storage->mutex);
g_assert (buffer->lock_count >=0);
buffer->lock_count--;
g_assert (buffer->lock_count >=0);
if (buffer->lock_count == 0 && gegl_buffer_is_shared (buffer))
- return gegl_tile_backend_file_unlock (GEGL_TILE_BACKEND_FILE (backend));
- return TRUE;
+ {
+ ret = gegl_tile_backend_file_unlock (GEGL_TILE_BACKEND_FILE (backend));
+ }
+ g_mutex_unlock (buffer->tile_storage->mutex);
+ return ret;
}
diff --git a/gegl/buffer/gegl-cache.c b/gegl/buffer/gegl-cache.c
index 0cf29b3..8505d19 100644
--- a/gegl/buffer/gegl-cache.c
+++ b/gegl/buffer/gegl-cache.c
@@ -191,6 +191,7 @@ static void
gegl_cache_init (GeglCache *self)
{
self->node = NULL;
+ self->mutex = g_mutex_new ();
/* thus providing a default value for GeglCache, that overrides the NULL
* from GeglBuffer */
@@ -228,6 +229,7 @@ finalize (GObject *gobject)
{
GeglCache *self = GEGL_CACHE (gobject);
+ g_mutex_free (self->mutex);
if (self->valid_region)
gegl_region_destroy (self->valid_region);
G_OBJECT_CLASS (gegl_cache_parent_class)->finalize (gobject);
@@ -248,7 +250,9 @@ node_invalidated (GeglNode *source,
gegl_region_destroy (region);
}
+ g_mutex_lock (cache->mutex);
g_signal_emit_by_name (cache, "invalidated", &expanded, NULL);
+ g_mutex_unlock (cache->mutex);
}
static void
@@ -262,6 +266,7 @@ set_property (GObject *gobject,
switch (property_id)
{
case PROP_NODE:
+ g_mutex_lock (self->mutex);
if (self->node)
{
gulong handler;
@@ -280,6 +285,7 @@ set_property (GObject *gobject,
self->node = GEGL_NODE (g_value_get_object (value));
g_signal_connect (G_OBJECT (self->node), "invalidated",
G_CALLBACK (node_invalidated), self);
+ g_mutex_unlock (self->mutex);
break;
case PROP_X:
@@ -377,6 +383,7 @@ gegl_cache_invalidate (GeglCache *self,
}
#endif
+ g_mutex_lock (self->mutex);
if (roi)
{
@@ -398,6 +405,7 @@ gegl_cache_invalidate (GeglCache *self,
g_signal_emit (self, gegl_cache_signals[INVALIDATED], 0,
&rect, NULL);
}
+ g_mutex_unlock (self->mutex);
}
void
@@ -407,6 +415,8 @@ gegl_cache_computed (GeglCache *self,
g_return_if_fail (GEGL_IS_CACHE (self));
g_return_if_fail (rect != NULL);
+ g_mutex_lock (self->mutex);
gegl_region_union_with_rect (self->valid_region, rect);
g_signal_emit (self, gegl_cache_signals[COMPUTED], 0, rect, NULL);
+ g_mutex_unlock (self->mutex);
}
diff --git a/gegl/buffer/gegl-cache.h b/gegl/buffer/gegl-cache.h
index 5e423a2..df759a7 100644
--- a/gegl/buffer/gegl-cache.h
+++ b/gegl/buffer/gegl-cache.h
@@ -38,6 +38,7 @@ struct _GeglCache
GeglNode *node;
const void *format;
GeglRegion *valid_region;
+ GMutex *mutex;
};
struct _GeglCacheClass
diff --git a/perf/tests/comp.c b/perf/tests/comp.c
index 5a62c04..c4f0801 100644
--- a/perf/tests/comp.c
+++ b/perf/tests/comp.c
@@ -15,7 +15,7 @@ main (gint argc,
bufferB = test_buffer (2048, 2048, babl_format ("RGBA float"));
buffer = test_buffer (2048, 2048, babl_format ("RGBA float"));
-#define ITERATIONS 6
+#define ITERATIONS 4
test_start ();
for (i=0;i< ITERATIONS;i++)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]