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



commit 62baffed984f5505b77896a104d269e0060047cc
Author: Ell <ell_se yahoo com>
Date:   Mon Nov 19 11:46:19 2018 -0500

    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()).

 app/core/gimp-parallel.cc | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/app/core/gimp-parallel.cc b/app/core/gimp-parallel.cc
index 777dd0d43a..3a88b51856 100644
--- a/app/core/gimp-parallel.cc
+++ b/app/core/gimp-parallel.cc
@@ -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" */


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