Commit d8ae5817 authored by Ell's avatar Ell

libgimp: make GimpTileBackendPlugin thread safe

The entire libgimp tile code is not thread safe.  For now, do the
easy thing, and protect GimpTileBackendPlugin with a mutex.
parent a30f8559
......@@ -34,6 +34,7 @@
struct _GimpTileBackendPluginPrivate
{
GMutex mutex;
GimpDrawable *drawable;
gboolean shadow;
gint mul;
......@@ -106,6 +107,8 @@ _gimp_tile_backend_plugin_init (GimpTileBackendPlugin *backend)
GimpTileBackendPluginPrivate);
source->command = gimp_tile_backend_plugin_command;
g_mutex_init (&backend->priv->mutex);
}
static void
......@@ -116,6 +119,8 @@ gimp_tile_backend_plugin_finalize (GObject *object)
if (backend->priv->drawable) /* This also causes a flush */
gimp_drawable_detach (backend->priv->drawable);
g_mutex_clear (&backend->priv->mutex);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -128,26 +133,40 @@ gimp_tile_backend_plugin_command (GeglTileSource *tile_store,
gpointer data)
{
GimpTileBackendPlugin *backend_plugin = GIMP_TILE_BACKEND_PLUGIN (tile_store);
gpointer result = NULL;
switch (command)
{
case GEGL_TILE_GET:
return gimp_tile_read_mul (backend_plugin, x, y);
g_mutex_lock (&backend_plugin->priv->mutex);
result = gimp_tile_read_mul (backend_plugin, x, y);
g_mutex_unlock (&backend_plugin->priv->mutex);
break;
case GEGL_TILE_SET:
g_mutex_lock (&backend_plugin->priv->mutex);
gimp_tile_write_mul (backend_plugin, x, y, gegl_tile_get_data (data));
gegl_tile_mark_as_stored (data);
g_mutex_unlock (&backend_plugin->priv->mutex);
break;
case GEGL_TILE_FLUSH:
g_mutex_lock (&backend_plugin->priv->mutex);
gimp_drawable_flush (backend_plugin->priv->drawable);
g_mutex_unlock (&backend_plugin->priv->mutex);
break;
default:
g_assert (command < GEGL_TILE_LAST_COMMAND && command >= 0);
}
return NULL;
return result;
}
static GeglTile *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment