Commit 15f73440 authored by Jehan's avatar Jehan

libgimp, libgimpbase: allow multi-threaded plugins by locking...

...protocol calls.
Some calls are waiting for answers, for instance plugin procedures, and
tiles which expects data and acknoledgement.
This would result in error messages such as:
"expected tile ack and received: 5" (5 is GP_PROC_RUN)
Typically because a thread would run a procedure while another would
receive tiles.
parent 4410ab0d
......@@ -1117,10 +1117,12 @@ gimp_run_procedure2 (const gchar *name,
proc_run.nparams = n_params;
proc_run.params = (GPParam *) params;
gp_lock ();
if (! gp_proc_run_write (_writechannel, &proc_run, NULL))
gimp_quit ();
gimp_read_expect_msg (&msg, GP_PROC_RETURN);
gp_unlock ();
proc_return = msg.data;
......
......@@ -200,6 +200,7 @@ gimp_tile_get (GimpTile *tile)
tile_req.tile_num = tile->tile_num;
tile_req.shadow = tile->shadow;
gp_lock ();
if (! gp_tile_req_write (_writechannel, &tile_req, NULL))
gimp_quit ();
......@@ -230,6 +231,7 @@ gimp_tile_get (GimpTile *tile)
if (! gp_tile_ack_write (_writechannel, NULL))
gimp_quit ();
gp_unlock ();
gimp_wire_destroy (&msg);
}
......@@ -248,6 +250,7 @@ gimp_tile_put (GimpTile *tile)
tile_req.tile_num = 0;
tile_req.shadow = 0;
gp_lock ();
if (! gp_tile_req_write (_writechannel, &tile_req, NULL))
gimp_quit ();
......@@ -280,6 +283,7 @@ gimp_tile_put (GimpTile *tile)
gimp_wire_destroy (&msg);
gimp_read_expect_msg (&msg, GP_TILE_ACK);
gp_unlock ();
gimp_wire_destroy (&msg);
}
......
......@@ -26,6 +26,7 @@
#include "gimpprotocol.h"
#include "gimpwire.h"
static GMutex readwrite_mutex;
static void _gp_quit_read (GIOChannel *channel,
GimpWireMessage *msg,
......@@ -1848,6 +1849,18 @@ gp_params_destroy (GPParam *params,
g_free (params);
}
void
gp_lock (void)
{
g_mutex_lock (&readwrite_mutex);
}
void
gp_unlock (void)
{
g_mutex_unlock (&readwrite_mutex);
}
/* has_init */
static void
......
......@@ -228,6 +228,9 @@ gboolean gp_has_init_write (GIOChannel *channel,
void gp_params_destroy (GPParam *params,
gint nparams);
void gp_lock (void);
void gp_unlock (void);
G_END_DECLS
......
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