[gimp/wip/animation: 99/145] libgimp, libgimpbase: allow multi-threaded plugins by locking...



commit 0310addccb4b1ae1414ce37235fb67fef0e0ecad
Author: Jehan <jehan girinstud io>
Date:   Sun May 21 15:13:33 2017 +0200

    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.

 libgimp/gimp.c             |    2 ++
 libgimp/gimptile.c         |    4 ++++
 libgimpbase/gimpprotocol.c |   13 +++++++++++++
 libgimpbase/gimpprotocol.h |    3 +++
 4 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index bebdbab..2080137 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -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;
 
diff --git a/libgimp/gimptile.c b/libgimp/gimptile.c
index 208956a..4c5c9e7 100644
--- a/libgimp/gimptile.c
+++ b/libgimp/gimptile.c
@@ -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);
 }
 
diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c
index 4058e46..e57ac2d 100644
--- a/libgimpbase/gimpprotocol.c
+++ b/libgimpbase/gimpprotocol.c
@@ -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
diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h
index 4d6bd50..e01edb3 100644
--- a/libgimpbase/gimpprotocol.h
+++ b/libgimpbase/gimpprotocol.h
@@ -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
 


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