added separate GMainLoops for waiting for extension_ack and for

2003-06-23  Michael Natterer  <mitch@gimp.org>

	* app/plug-in/plug-in.[ch]: added separate GMainLoops for waiting
	for extension_ack and for procedure_run's return value. The stack
	of main loops is currently unused, it will be used for temp_proc
	return values (which are currently disabled for no good reason).
	Removed the boolean "recurse" and "starting_ext" states because
	they are redundant now (we check for the presence of the dedicated
	main loops instead).

	* app/plug-in/plug-in-message.c
	* app/plug-in/plug-in-progress.c
	* app/plug-in/plug-in-run.c: changed accordingly.
This commit is contained in:
Michael Natterer 2003-06-23 18:27:03 +00:00 committed by Michael Natterer
parent 1d5127dfe9
commit ba91aeb86b
12 changed files with 169 additions and 125 deletions

View File

@ -1,3 +1,17 @@
2003-06-23 Michael Natterer <mitch@gimp.org>
* app/plug-in/plug-in.[ch]: added separate GMainLoops for waiting
for extension_ack and for procedure_run's return value. The stack
of main loops is currently unused, it will be used for temp_proc
return values (which are currently disabled for no good reason).
Removed the boolean "recurse" and "starting_ext" states because
they are redundant now (we check for the presence of the dedicated
main loops instead).
* app/plug-in/plug-in-message.c
* app/plug-in/plug-in-progress.c
* app/plug-in/plug-in-run.c: changed accordingly.
2003-06-23 Sven Neumann <sven@gimp.org>
* data/misc/gimp.desktop.in.in: announce the fact that we

View File

@ -398,7 +398,7 @@ static void
plug_in_handle_proc_return_priv (PlugIn *plug_in,
GPProcReturn *proc_return)
{
if (plug_in->recurse)
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
{
plug_in->return_vals = plug_in_params_to_args (proc_return->params,
proc_return->nparams,
@ -442,8 +442,8 @@ plug_in_handle_proc_return (PlugIn *plug_in,
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
if (plug_in->recurse)
plug_in_main_loop_quit (plug_in);
if (plug_in->recurse_main_loop)
g_main_loop_quit (plug_in->recurse_main_loop);
plug_in_close (plug_in, FALSE);
}
@ -453,7 +453,7 @@ static void
plug_in_handle_temp_proc_return (PlugIn *plug_in,
GPProcReturn *proc_return)
{
if (plug_in->in_temp_proc)
if (plug_in->temp_main_loops)
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
@ -780,9 +780,9 @@ plug_in_handle_proc_uninstall (PlugIn *plug_in,
static void
plug_in_handle_extension_ack (PlugIn *plug_in)
{
if (plug_in->starting_ext)
if (plug_in->ext_main_loop)
{
plug_in_main_loop_quit (plug_in);
g_main_loop_quit (plug_in->ext_main_loop);
}
else
{

View File

@ -100,7 +100,7 @@ static void
plug_in_progress_cancel (GtkWidget *widget,
PlugIn *plug_in)
{
if (plug_in->recurse)
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
{
plug_in->return_vals = g_new (Argument, 1);
plug_in->n_return_vals = 1;

View File

@ -265,8 +265,6 @@ plug_in_new (Gimp *gimp,
plug_in->query = FALSE;
plug_in->init = FALSE;
plug_in->synchronous = FALSE;
plug_in->recurse = FALSE;
plug_in->starting_ext = FALSE;
plug_in->pid = 0;
plug_in->name = g_path_get_basename (prog);
@ -283,7 +281,10 @@ plug_in_new (Gimp *gimp,
plug_in->temp_proc_defs = NULL;
plug_in->current_temp_proc = NULL;
plug_in->main_loops = NULL;
plug_in->ext_main_loop = NULL;
plug_in->recurse_main_loop = NULL;
plug_in->temp_main_loops = NULL;
plug_in->return_vals = NULL;
plug_in->n_return_vals = 0;
@ -396,10 +397,10 @@ plug_in_open (PlugIn *plug_in)
/* Remember the file descriptors for the pipes.
*/
read_fd =
g_strdup_printf ("%d", g_io_channel_unix_get_fd (plug_in->his_read));
write_fd =
g_strdup_printf ("%d", g_io_channel_unix_get_fd (plug_in->his_write));
read_fd = g_strdup_printf ("%d",
g_io_channel_unix_get_fd (plug_in->his_read));
write_fd = g_strdup_printf ("%d",
g_io_channel_unix_get_fd (plug_in->his_write));
/* Set the rest of the command line arguments.
* FIXME: this is ugly. Pass in the mode as a separate argument?
@ -607,15 +608,27 @@ plug_in_close (PlugIn *plug_in,
if (plug_in->progress)
plug_in_progress_end (plug_in);
if (plug_in->recurse)
while (plug_in->temp_main_loops)
{
while (plug_in->main_loops)
{
g_warning ("plug_in_close: quitting stale main loop\n");
plug_in_main_loop_quit (plug_in);
}
g_warning ("plug_in_close: plug-in aborted before sending its "
"temporary procedure return values");
plug_in_main_loop_quit (plug_in);
}
plug_in->recurse = FALSE;
if (plug_in->recurse_main_loop &&
g_main_loop_is_running (plug_in->recurse_main_loop))
{
g_warning ("plug_in_close: plug-in aborted before sending its "
"procedure return values");
g_main_loop_quit (plug_in->recurse_main_loop);
}
if (plug_in->ext_main_loop &&
g_main_loop_is_running (plug_in->ext_main_loop))
{
g_warning ("plug_in_close: extension aborted before sending its "
"extension_ack message");
g_main_loop_quit (plug_in->ext_main_loop);
}
plug_in->synchronous = FALSE;
@ -816,13 +829,9 @@ plug_in_pop (Gimp *gimp)
}
if (gimp->plug_in_stack)
{
gimp->current_plug_in = gimp->plug_in_stack->data;
}
gimp->current_plug_in = gimp->plug_in_stack->data;
else
{
gimp->current_plug_in = NULL;
}
gimp->current_plug_in = NULL;
}
void
@ -834,7 +843,8 @@ plug_in_main_loop (PlugIn *plug_in)
main_loop = g_main_loop_new (NULL, FALSE);
plug_in->main_loops = g_list_prepend (plug_in->main_loops, main_loop);
plug_in->temp_main_loops = g_list_prepend (plug_in->temp_main_loops,
main_loop);
gimp_threads_leave (plug_in->gimp);
g_main_loop_run (main_loop);
@ -846,18 +856,22 @@ plug_in_main_loop (PlugIn *plug_in)
void
plug_in_main_loop_quit (PlugIn *plug_in)
{
GMainLoop *main_loop;
g_return_if_fail (plug_in != NULL);
if (! plug_in->main_loops)
if (! plug_in->temp_main_loops)
{
g_warning ("plug_in_main_loop_quit: called without a main loop running");
g_warning ("plug_in_main_loop_quit: called without a temp main loop running");
return;
}
g_main_loop_quit ((GMainLoop *) plug_in->main_loops->data);
main_loop = (GMainLoop *) plug_in->temp_main_loops->data;
plug_in->main_loops = g_list_remove (plug_in->main_loops,
plug_in->main_loops->data);
g_main_loop_quit (main_loop);
plug_in->temp_main_loops = g_list_remove (plug_in->temp_main_loops,
main_loop);
}
gchar *

View File

@ -38,8 +38,6 @@ struct _PlugIn
guint query : 1; /* Are we querying the plug-in? */
guint init : 1; /* Are we initialing the plug-in? */
guint synchronous : 1; /* Is the plug-in running synchronously? */
guint recurse : 1; /* Do we have an own GMainLoop? */
guint starting_ext : 1; /* Does the plug-in wait for extension_ack?*/
pid_t pid; /* Plug-in's process id */
gchar *name; /* Plug-in's name */
@ -58,7 +56,10 @@ struct _PlugIn
GSList *temp_proc_defs; /* Temporary procedures */
ProcRecord *current_temp_proc;/* The temp proc the plug-in is busy with */
GList *main_loops; /* Stack of recursive main loops */
GMainLoop *ext_main_loop; /* for waiting for extension_ack */
GMainLoop *recurse_main_loop;/* for waiting for proc_return */
GList *temp_main_loops; /* for waiting for temp_proc_returns */
Argument *return_vals; /* The return value we wait for */
gint n_return_vals;
@ -93,7 +94,7 @@ void plug_in_pop (Gimp *gimp);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);

View File

@ -93,8 +93,6 @@ plug_in_run (Gimp *gimp,
goto done;
}
plug_in->recurse = synchronous;
config.version = GP_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
@ -126,19 +124,29 @@ plug_in_run (Gimp *gimp,
*/
if (proc_rec->proc_type == GIMP_EXTENSION)
{
plug_in->starting_ext = TRUE;
plug_in->ext_main_loop = g_main_loop_new (NULL, FALSE);
plug_in_main_loop (plug_in);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->ext_main_loop);
gimp_threads_enter (gimp);
plug_in->starting_ext = FALSE;
g_main_loop_unref (plug_in->ext_main_loop);
plug_in->ext_main_loop = NULL;
}
/* If this plug-in is requested to run synchronously,
* wait for its return values
*/
if (plug_in->recurse)
if (synchronous)
{
plug_in_main_loop (plug_in);
plug_in->recurse_main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->recurse_main_loop);
gimp_threads_enter (gimp);
g_main_loop_unref (plug_in->recurse_main_loop);
plug_in->recurse_main_loop = NULL;
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
}
@ -206,7 +214,6 @@ plug_in_temp_run (ProcRecord *proc_rec,
if (plug_in)
{
GPProcRun proc_run;
gboolean old_recurse;
if (plug_in->current_temp_proc)
{
@ -229,26 +236,19 @@ plug_in_temp_run (ProcRecord *proc_rec,
plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE);
old_recurse = plug_in->recurse;
plug_in->recurse = TRUE;
#ifdef ENABLE_TEMP_RETURN
plug_in_ref (plug_in);
#ifdef ENABLE_TEMP_RETURN
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (proc_rec);
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
#else
return_vals = procedural_db_return_args (proc_rec, TRUE);
#endif
plug_in->recurse = old_recurse;
plug_in->current_temp_proc = NULL;
#ifdef ENABLE_TEMP_RETURN
plug_in_unref (plug_in);
#endif
}
done:

View File

@ -93,8 +93,6 @@ plug_in_run (Gimp *gimp,
goto done;
}
plug_in->recurse = synchronous;
config.version = GP_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
@ -126,19 +124,29 @@ plug_in_run (Gimp *gimp,
*/
if (proc_rec->proc_type == GIMP_EXTENSION)
{
plug_in->starting_ext = TRUE;
plug_in->ext_main_loop = g_main_loop_new (NULL, FALSE);
plug_in_main_loop (plug_in);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->ext_main_loop);
gimp_threads_enter (gimp);
plug_in->starting_ext = FALSE;
g_main_loop_unref (plug_in->ext_main_loop);
plug_in->ext_main_loop = NULL;
}
/* If this plug-in is requested to run synchronously,
* wait for its return values
*/
if (plug_in->recurse)
if (synchronous)
{
plug_in_main_loop (plug_in);
plug_in->recurse_main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->recurse_main_loop);
gimp_threads_enter (gimp);
g_main_loop_unref (plug_in->recurse_main_loop);
plug_in->recurse_main_loop = NULL;
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
}
@ -206,7 +214,6 @@ plug_in_temp_run (ProcRecord *proc_rec,
if (plug_in)
{
GPProcRun proc_run;
gboolean old_recurse;
if (plug_in->current_temp_proc)
{
@ -229,26 +236,19 @@ plug_in_temp_run (ProcRecord *proc_rec,
plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE);
old_recurse = plug_in->recurse;
plug_in->recurse = TRUE;
#ifdef ENABLE_TEMP_RETURN
plug_in_ref (plug_in);
#ifdef ENABLE_TEMP_RETURN
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (proc_rec);
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
#else
return_vals = procedural_db_return_args (proc_rec, TRUE);
#endif
plug_in->recurse = old_recurse;
plug_in->current_temp_proc = NULL;
#ifdef ENABLE_TEMP_RETURN
plug_in_unref (plug_in);
#endif
}
done:

View File

@ -398,7 +398,7 @@ static void
plug_in_handle_proc_return_priv (PlugIn *plug_in,
GPProcReturn *proc_return)
{
if (plug_in->recurse)
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
{
plug_in->return_vals = plug_in_params_to_args (proc_return->params,
proc_return->nparams,
@ -442,8 +442,8 @@ plug_in_handle_proc_return (PlugIn *plug_in,
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
if (plug_in->recurse)
plug_in_main_loop_quit (plug_in);
if (plug_in->recurse_main_loop)
g_main_loop_quit (plug_in->recurse_main_loop);
plug_in_close (plug_in, FALSE);
}
@ -453,7 +453,7 @@ static void
plug_in_handle_temp_proc_return (PlugIn *plug_in,
GPProcReturn *proc_return)
{
if (plug_in->in_temp_proc)
if (plug_in->temp_main_loops)
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
@ -780,9 +780,9 @@ plug_in_handle_proc_uninstall (PlugIn *plug_in,
static void
plug_in_handle_extension_ack (PlugIn *plug_in)
{
if (plug_in->starting_ext)
if (plug_in->ext_main_loop)
{
plug_in_main_loop_quit (plug_in);
g_main_loop_quit (plug_in->ext_main_loop);
}
else
{

View File

@ -100,7 +100,7 @@ static void
plug_in_progress_cancel (GtkWidget *widget,
PlugIn *plug_in)
{
if (plug_in->recurse)
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
{
plug_in->return_vals = g_new (Argument, 1);
plug_in->n_return_vals = 1;

View File

@ -93,8 +93,6 @@ plug_in_run (Gimp *gimp,
goto done;
}
plug_in->recurse = synchronous;
config.version = GP_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
@ -126,19 +124,29 @@ plug_in_run (Gimp *gimp,
*/
if (proc_rec->proc_type == GIMP_EXTENSION)
{
plug_in->starting_ext = TRUE;
plug_in->ext_main_loop = g_main_loop_new (NULL, FALSE);
plug_in_main_loop (plug_in);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->ext_main_loop);
gimp_threads_enter (gimp);
plug_in->starting_ext = FALSE;
g_main_loop_unref (plug_in->ext_main_loop);
plug_in->ext_main_loop = NULL;
}
/* If this plug-in is requested to run synchronously,
* wait for its return values
*/
if (plug_in->recurse)
if (synchronous)
{
plug_in_main_loop (plug_in);
plug_in->recurse_main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->recurse_main_loop);
gimp_threads_enter (gimp);
g_main_loop_unref (plug_in->recurse_main_loop);
plug_in->recurse_main_loop = NULL;
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
}
@ -206,7 +214,6 @@ plug_in_temp_run (ProcRecord *proc_rec,
if (plug_in)
{
GPProcRun proc_run;
gboolean old_recurse;
if (plug_in->current_temp_proc)
{
@ -229,26 +236,19 @@ plug_in_temp_run (ProcRecord *proc_rec,
plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE);
old_recurse = plug_in->recurse;
plug_in->recurse = TRUE;
#ifdef ENABLE_TEMP_RETURN
plug_in_ref (plug_in);
#ifdef ENABLE_TEMP_RETURN
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (proc_rec);
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
#else
return_vals = procedural_db_return_args (proc_rec, TRUE);
#endif
plug_in->recurse = old_recurse;
plug_in->current_temp_proc = NULL;
#ifdef ENABLE_TEMP_RETURN
plug_in_unref (plug_in);
#endif
}
done:

View File

@ -265,8 +265,6 @@ plug_in_new (Gimp *gimp,
plug_in->query = FALSE;
plug_in->init = FALSE;
plug_in->synchronous = FALSE;
plug_in->recurse = FALSE;
plug_in->starting_ext = FALSE;
plug_in->pid = 0;
plug_in->name = g_path_get_basename (prog);
@ -283,7 +281,10 @@ plug_in_new (Gimp *gimp,
plug_in->temp_proc_defs = NULL;
plug_in->current_temp_proc = NULL;
plug_in->main_loops = NULL;
plug_in->ext_main_loop = NULL;
plug_in->recurse_main_loop = NULL;
plug_in->temp_main_loops = NULL;
plug_in->return_vals = NULL;
plug_in->n_return_vals = 0;
@ -396,10 +397,10 @@ plug_in_open (PlugIn *plug_in)
/* Remember the file descriptors for the pipes.
*/
read_fd =
g_strdup_printf ("%d", g_io_channel_unix_get_fd (plug_in->his_read));
write_fd =
g_strdup_printf ("%d", g_io_channel_unix_get_fd (plug_in->his_write));
read_fd = g_strdup_printf ("%d",
g_io_channel_unix_get_fd (plug_in->his_read));
write_fd = g_strdup_printf ("%d",
g_io_channel_unix_get_fd (plug_in->his_write));
/* Set the rest of the command line arguments.
* FIXME: this is ugly. Pass in the mode as a separate argument?
@ -607,15 +608,27 @@ plug_in_close (PlugIn *plug_in,
if (plug_in->progress)
plug_in_progress_end (plug_in);
if (plug_in->recurse)
while (plug_in->temp_main_loops)
{
while (plug_in->main_loops)
{
g_warning ("plug_in_close: quitting stale main loop\n");
plug_in_main_loop_quit (plug_in);
}
g_warning ("plug_in_close: plug-in aborted before sending its "
"temporary procedure return values");
plug_in_main_loop_quit (plug_in);
}
plug_in->recurse = FALSE;
if (plug_in->recurse_main_loop &&
g_main_loop_is_running (plug_in->recurse_main_loop))
{
g_warning ("plug_in_close: plug-in aborted before sending its "
"procedure return values");
g_main_loop_quit (plug_in->recurse_main_loop);
}
if (plug_in->ext_main_loop &&
g_main_loop_is_running (plug_in->ext_main_loop))
{
g_warning ("plug_in_close: extension aborted before sending its "
"extension_ack message");
g_main_loop_quit (plug_in->ext_main_loop);
}
plug_in->synchronous = FALSE;
@ -816,13 +829,9 @@ plug_in_pop (Gimp *gimp)
}
if (gimp->plug_in_stack)
{
gimp->current_plug_in = gimp->plug_in_stack->data;
}
gimp->current_plug_in = gimp->plug_in_stack->data;
else
{
gimp->current_plug_in = NULL;
}
gimp->current_plug_in = NULL;
}
void
@ -834,7 +843,8 @@ plug_in_main_loop (PlugIn *plug_in)
main_loop = g_main_loop_new (NULL, FALSE);
plug_in->main_loops = g_list_prepend (plug_in->main_loops, main_loop);
plug_in->temp_main_loops = g_list_prepend (plug_in->temp_main_loops,
main_loop);
gimp_threads_leave (plug_in->gimp);
g_main_loop_run (main_loop);
@ -846,18 +856,22 @@ plug_in_main_loop (PlugIn *plug_in)
void
plug_in_main_loop_quit (PlugIn *plug_in)
{
GMainLoop *main_loop;
g_return_if_fail (plug_in != NULL);
if (! plug_in->main_loops)
if (! plug_in->temp_main_loops)
{
g_warning ("plug_in_main_loop_quit: called without a main loop running");
g_warning ("plug_in_main_loop_quit: called without a temp main loop running");
return;
}
g_main_loop_quit ((GMainLoop *) plug_in->main_loops->data);
main_loop = (GMainLoop *) plug_in->temp_main_loops->data;
plug_in->main_loops = g_list_remove (plug_in->main_loops,
plug_in->main_loops->data);
g_main_loop_quit (main_loop);
plug_in->temp_main_loops = g_list_remove (plug_in->temp_main_loops,
main_loop);
}
gchar *

View File

@ -38,8 +38,6 @@ struct _PlugIn
guint query : 1; /* Are we querying the plug-in? */
guint init : 1; /* Are we initialing the plug-in? */
guint synchronous : 1; /* Is the plug-in running synchronously? */
guint recurse : 1; /* Do we have an own GMainLoop? */
guint starting_ext : 1; /* Does the plug-in wait for extension_ack?*/
pid_t pid; /* Plug-in's process id */
gchar *name; /* Plug-in's name */
@ -58,7 +56,10 @@ struct _PlugIn
GSList *temp_proc_defs; /* Temporary procedures */
ProcRecord *current_temp_proc;/* The temp proc the plug-in is busy with */
GList *main_loops; /* Stack of recursive main loops */
GMainLoop *ext_main_loop; /* for waiting for extension_ack */
GMainLoop *recurse_main_loop;/* for waiting for proc_return */
GList *temp_main_loops; /* for waiting for temp_proc_returns */
Argument *return_vals; /* The return value we wait for */
gint n_return_vals;
@ -93,7 +94,7 @@ void plug_in_pop (Gimp *gimp);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);