[gimp] app: add gimp_parallel_run_async_independent_full()



commit fa2e4dcce0bd5e27022b18ceb9f49b2cec2e9fec
Author: Ell <ell_se yahoo com>
Date:   Tue Mar 5 23:39:43 2019 -0500

    app: add gimp_parallel_run_async_independent_full()
    
    ... which is equivalent to gimp_parallel_run_async_independent(),
    except that it takes an additional "priority" parameter, which
    specifies the task's priority, with 0 being the default priority,
    and lower values indicating higher priority.  Unlike
    gimp_parallel_run_async_full(), the priority parameter doesn't
    directly control the task's priority in a queue, but rather, we use
    it to control the priority of the task's dedicated thread, on
    supported platforms (previously, all independent async tasks would
    run with low priority.)
    
    Use low priority when loading fonts, which can take a long time, to
    keep the existing behavior.

 app/core/gimp-parallel.cc  | 27 ++++++++++++++++++----
 app/core/gimp-parallel.h   | 56 ++++++++++++++++++++++++++++------------------
 app/text/gimpfontfactory.c |  3 ++-
 3 files changed, 59 insertions(+), 27 deletions(-)
---
diff --git a/app/core/gimp-parallel.cc b/app/core/gimp-parallel.cc
index 3a88b51856..aca95fe9a3 100644
--- a/app/core/gimp-parallel.cc
+++ b/app/core/gimp-parallel.cc
@@ -184,6 +184,14 @@ gimp_parallel_run_async_full (gint                     priority,
 GimpAsync *
 gimp_parallel_run_async_independent (GimpParallelRunAsyncFunc func,
                                      gpointer                 user_data)
+{
+  return gimp_parallel_run_async_independent_full (0, func, user_data);
+}
+
+GimpAsync *
+gimp_parallel_run_async_independent_full (gint                     priority,
+                                          GimpParallelRunAsyncFunc func,
+                                          gpointer                 user_data)
 {
   GimpAsync                *async;
   GimpParallelRunAsyncTask *task;
@@ -196,6 +204,7 @@ gimp_parallel_run_async_independent (GimpParallelRunAsyncFunc func,
   task = g_slice_new0 (GimpParallelRunAsyncTask);
 
   task->async     = GIMP_ASYNC (g_object_ref (async));
+  task->priority  = priority;
   task->func      = func;
   task->user_data = user_data;
 
@@ -205,12 +214,22 @@ gimp_parallel_run_async_independent (GimpParallelRunAsyncFunc func,
     {
       GimpParallelRunAsyncTask *task = (GimpParallelRunAsyncTask *) data;
 
-      /* lower the thread's priority */
+      /* adjust the thread's priority */
 #if defined (G_OS_WIN32)
-      SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN);
+      if (task->priority < 0)
+        {
+          SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN);
+        }
+      else if (task->priority > 0)
+        {
+          SetThreadPriority (GetCurrentThread (), THREAD_MODE_ABOVE_NORMAL);
+        }
 #elif defined (HAVE_UNISTD_H) && defined (__gnu_linux__)
-      nice (+10) != -1;
-              /* ^-- avoid "unused result" warning */
+      if (task->priority)
+        {
+          nice (task->priority) != -1;
+                             /* ^-- avoid "unused result" warning */
+        }
 #endif
 
       while (gimp_parallel_run_async_execute_task (task));
diff --git a/app/core/gimp-parallel.h b/app/core/gimp-parallel.h
index c538778462..4df9efb996 100644
--- a/app/core/gimp-parallel.h
+++ b/app/core/gimp-parallel.h
@@ -26,17 +26,20 @@ typedef void (* GimpParallelRunAsyncFunc) (GimpAsync *async,
                                            gpointer   user_data);
 
 
-void        gimp_parallel_init                  (Gimp                     *gimp);
-void        gimp_parallel_exit                  (Gimp                     *gimp);
-
-GimpAsync * gimp_parallel_run_async             (GimpParallelRunAsyncFunc  func,
-                                                 gpointer                  user_data);
-GimpAsync * gimp_parallel_run_async_full        (gint                      priority,
-                                                 GimpParallelRunAsyncFunc  func,
-                                                 gpointer                  user_data,
-                                                 GDestroyNotify            user_data_destroy_func);
-GimpAsync * gimp_parallel_run_async_independent (GimpParallelRunAsyncFunc  func,
-                                                 gpointer                  user_data);
+void        gimp_parallel_init                       (Gimp                     *gimp);
+void        gimp_parallel_exit                       (Gimp                     *gimp);
+
+GimpAsync * gimp_parallel_run_async                  (GimpParallelRunAsyncFunc  func,
+                                                      gpointer                  user_data);
+GimpAsync * gimp_parallel_run_async_full             (gint                      priority,
+                                                      GimpParallelRunAsyncFunc  func,
+                                                      gpointer                  user_data,
+                                                      GDestroyNotify            user_data_destroy_func);
+GimpAsync * gimp_parallel_run_async_independent      (GimpParallelRunAsyncFunc  func,
+                                                      gpointer                  user_data);
+GimpAsync * gimp_parallel_run_async_independent_full (gint                      priority,
+                                                      GimpParallelRunAsyncFunc  func,
+                                                      gpointer                  user_data);
 
 
 #ifdef __cplusplus
@@ -121,24 +124,33 @@ gimp_parallel_run_async_full (gint                 priority,
 
 template <class ParallelRunAsyncFunc>
 inline GimpAsync *
-gimp_parallel_run_async_independent (ParallelRunAsyncFunc func)
+gimp_parallel_run_async_independent_full (gint                 priority,
+                                          ParallelRunAsyncFunc func)
 {
   ParallelRunAsyncFunc *func_copy = g_new (ParallelRunAsyncFunc, 1);
 
   new (func_copy) ParallelRunAsyncFunc (func);
 
-  return gimp_parallel_run_async_independent ([] (GimpAsync *async,
-                                                  gpointer   user_data)
-                                              {
-                                                ParallelRunAsyncFunc *func_copy =
-                                                  (ParallelRunAsyncFunc *) user_data;
+  return gimp_parallel_run_async_independent_full (priority,
+                                                   [] (GimpAsync *async,
+                                                       gpointer   user_data)
+                                                   {
+                                                     ParallelRunAsyncFunc *func_copy =
+                                                       (ParallelRunAsyncFunc *) user_data;
 
-                                                (*func_copy) (async);
+                                                     (*func_copy) (async);
+
+                                                     func_copy->~ParallelRunAsyncFunc ();
+                                                     g_free (func_copy);
+                                                   },
+                                                   func_copy);
+}
 
-                                                func_copy->~ParallelRunAsyncFunc ();
-                                                g_free (func_copy);
-                                              },
-                                              func_copy);
+template <class ParallelRunAsyncFunc>
+inline GimpAsync *
+gimp_parallel_run_async_independent (ParallelRunAsyncFunc func)
+{
+  return gimp_parallel_run_async_independent_full (0, func);
 }
 
 }
diff --git a/app/text/gimpfontfactory.c b/app/text/gimpfontfactory.c
index 1ca0660b11..de37723e5f 100644
--- a/app/text/gimpfontfactory.c
+++ b/app/text/gimpfontfactory.c
@@ -332,7 +332,8 @@ gimp_font_factory_load (GimpFontFactory  *factory,
    * in the case a cache rebuild is to be done it will not block
    * the UI.
    */
-  async = gimp_parallel_run_async_independent (
+  async = gimp_parallel_run_async_independent_full (
+    +10,
     (GimpParallelRunAsyncFunc) gimp_font_factory_load_async,
     config);
 


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