app: in gimp-parallel, boost priority of waited-upon asyncs

When an async that was created through
gimp_parallel_run_async[_full](), and whose execution is still
pending, is being waited-upon, maximize its priority so that it
gets executed before all other pending asyncs.

Note that we deliberately don't simply execute the async in the
calling thread in this case, to allow timed-waits to fail (which is
especially important for gimp_wait()).
This commit is contained in:
Ell 2018-11-19 11:46:19 -05:00
parent 965da12b35
commit 62baffed98
1 changed files with 33 additions and 0 deletions

View File

@ -83,6 +83,7 @@ static GimpParallelRunAsyncTask * gimp_parallel_run_async_dequeue_task (void);
static gboolean gimp_parallel_run_async_execute_task (GimpParallelRunAsyncTask *task);
static void gimp_parallel_run_async_abort_task (GimpParallelRunAsyncTask *task);
static void gimp_parallel_run_async_cancel (GimpAsync *async);
static void gimp_parallel_run_async_waiting (GimpAsync *async);
/* local variables */
@ -160,6 +161,9 @@ gimp_parallel_run_async_full (gint priority,
g_signal_connect_after (async, "cancel",
G_CALLBACK (gimp_parallel_run_async_cancel),
NULL);
g_signal_connect_after (async, "waiting",
G_CALLBACK (gimp_parallel_run_async_waiting),
NULL);
g_mutex_lock (&gimp_parallel_run_async_mutex);
@ -498,4 +502,33 @@ gimp_parallel_run_async_cancel (GimpAsync *async)
gimp_parallel_run_async_abort_task (task);
}
static void
gimp_parallel_run_async_waiting (GimpAsync *async)
{
GList *link;
link = (GList *) g_object_get_data (G_OBJECT (async),
"gimp-parallel-run-async-link");
if (! link)
return;
g_mutex_lock (&gimp_parallel_run_async_mutex);
link = (GList *) g_object_get_data (G_OBJECT (async),
"gimp-parallel-run-async-link");
if (link)
{
GimpParallelRunAsyncTask *task = (GimpParallelRunAsyncTask *) link->data;
task->priority = G_MININT;
g_queue_unlink (&gimp_parallel_run_async_queue, link);
g_queue_push_head_link (&gimp_parallel_run_async_queue, link);
}
g_mutex_unlock (&gimp_parallel_run_async_mutex);
}
} /* extern "C" */