[gimp/gimp-2-10] app: lower thread priority of independent async operations



commit 85a1b1ece7312bcfdd2bcc60517f092a368c45e8
Author: Ell <ell_se yahoo com>
Date:   Tue May 29 09:42:03 2018 -0400

    app: lower thread priority of independent async operations
    
    In gimp_parallel_run_async(), lower the priority of threads
    executing independent async operations.  Independent operations
    are generally potentially long-standing background tasks, which we
    don't want to bog down the rest of the program.
    
    This is currently only implemented on Linux and Windows.

 app/core/gimp-parallel.cc | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/app/core/gimp-parallel.cc b/app/core/gimp-parallel.cc
index 424d20ec73..19c917595d 100644
--- a/app/core/gimp-parallel.cc
+++ b/app/core/gimp-parallel.cc
@@ -24,6 +24,14 @@
 #include <gio/gio.h>
 #include <gegl.h>
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 extern "C"
 {
 
@@ -174,7 +182,22 @@ gimp_parallel_run_async (gboolean                 independent,
     {
       GThread *thread = g_thread_new (
         "async-ind",
-        (GThreadFunc) gimp_parallel_run_async_execute_task,
+        [] (gpointer data) -> gpointer
+        {
+          GimpParallelRunAsyncTask *task = (GimpParallelRunAsyncTask *) data;
+
+          /* lower the thread's priority */
+#if defined (G_OS_WIN32)
+          SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN);
+#elif defined (HAVE_UNISTD_H) && defined (__gnu_linux__)
+          nice (+10) != -1;
+                  /* ^-- avoid "unused result" warning */
+#endif
+
+          gimp_parallel_run_async_execute_task (task);
+
+          return NULL;
+        },
         task);
 
       gimp_async_add_callback (async,


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