[gegl] sampler: make gegl_buffer_sample_cleanup() thread safe
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] sampler: make gegl_buffer_sample_cleanup() thread safe
- Date: Thu, 29 Jun 2017 08:10:40 +0000 (UTC)
commit 651e5eecacbaa720d82558a23574b5c3df1f3078
Author: Ell <ell_se yahoo com>
Date: Thu Jun 29 03:54:35 2017 -0400
sampler: make gegl_buffer_sample_cleanup() thread safe
... w.r.t. gegl_buffer_sample_foo()
Use the same mutex that guards gegl_buffer_sample(_at_level) in
gegl_buffer_sample_cleanup(), so that they can be safely called
concurrently. This currently happens in certain ops when using
multithreading; this is probably not a very good thing to begin
with, but at least it doesn't crash anymore.
gegl/buffer/gegl-buffer-access.c | 12 ------------
gegl/buffer/gegl-sampler.c | 32 +++++++++++++++++++++++++++++---
2 files changed, 29 insertions(+), 15 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 8c3473e..2c02d44 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1559,18 +1559,6 @@ gegl_buffer_get (GeglBuffer *buffer,
gegl_buffer_unlock (buffer);
}
-void
-gegl_buffer_sample_cleanup (GeglBuffer *buffer)
-{
- g_return_if_fail (GEGL_IS_BUFFER (buffer));
-
- if (buffer->sampler)
- {
- g_object_unref (buffer->sampler);
- buffer->sampler = NULL;
- }
-}
-
static void
gegl_buffer_copy2 (GeglBuffer *src,
const GeglRectangle *src_rect,
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 2364380..aa47a9a 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -519,6 +519,8 @@ gegl_sampler_gtype_from_enum (GeglSamplerType sampler_type)
}
}
+static GMutex gegl_buffer_sampler_mutex = {0,};
+
void
gegl_buffer_sample_at_level (GeglBuffer *buffer,
gdouble x,
@@ -539,7 +541,6 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
return;
}*/
- static GMutex mutex = {0,};
gboolean threaded = gegl_config_threads ()>1;
@@ -553,7 +554,7 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
}
if (threaded)
- g_mutex_lock (&mutex);
+ g_mutex_lock (&gegl_buffer_sampler_mutex);
/* unset the cached sampler if it dosn't match the needs */
if (buffer->sampler != NULL &&
@@ -582,7 +583,7 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
buffer->sampler->get(buffer->sampler, x, y, scale, dest, repeat_mode);
if (threaded)
- g_mutex_unlock (&mutex);
+ g_mutex_unlock (&gegl_buffer_sampler_mutex);
}
@@ -599,6 +600,31 @@ gegl_buffer_sample (GeglBuffer *buffer,
gegl_buffer_sample_at_level (buffer, x, y, scale, dest, format, 0, sampler_type, repeat_mode);
}
+void
+gegl_buffer_sample_cleanup (GeglBuffer *buffer)
+{
+ gboolean threaded;
+
+ g_return_if_fail (GEGL_IS_BUFFER (buffer));
+
+ if (! buffer->sampler)
+ return;
+
+ threaded = gegl_config_threads ()>1;
+
+ if (threaded)
+ g_mutex_lock (&gegl_buffer_sampler_mutex);
+
+ if (buffer->sampler)
+ {
+ g_object_unref (buffer->sampler);
+ buffer->sampler = NULL;
+ }
+
+ if (threaded)
+ g_mutex_unlock (&gegl_buffer_sampler_mutex);
+}
+
GeglSampler *
gegl_buffer_sampler_new_at_level (GeglBuffer *buffer,
const Babl *format,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]