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.
This commit is contained in:
Ell 2019-03-05 23:39:43 -05:00
parent b0de51b6bf
commit fa2e4dcce0
3 changed files with 58 additions and 26 deletions

View File

@ -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));

View File

@ -26,17 +26,20 @@ typedef void (* GimpParallelRunAsyncFunc) (GimpAsync *async,
gpointer user_data);
void gimp_parallel_init (Gimp *gimp);
void gimp_parallel_exit (Gimp *gimp);
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 (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);
}
}

View File

@ -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);