Commit 4dae2d82 authored by Dan Winship's avatar Dan Winship

gtask: re-fix tasks-blocking-other-tasks

The new "slowly add more task threads" code doesn't fully deal with
apps that queue lots and lots of tasks which then block on tasks from
their task threads. Fix this by bringing back the "task is blocking
other task" check and making sure that such tasks get bumped to the
front of the queue.
parent 556705cb
......@@ -559,6 +559,7 @@ struct _GTask {
gboolean thread_cancelled;
gboolean synchronous;
gboolean thread_complete;
gboolean blocking_other_task;
GError *error;
union {
......@@ -592,6 +593,7 @@ G_DEFINE_TYPE_WITH_CODE (GTask, g_task, G_TYPE_OBJECT,
static GThreadPool *task_pool;
static GMutex task_pool_mutex;
static GPrivate task_private = G_PRIVATE_INIT (NULL);
static GSource *task_pool_manager;
static guint64 task_wait_time;
static gint tasks_running;
......@@ -1241,6 +1243,7 @@ task_pool_manager_timeout (gpointer user_data)
static void
g_task_thread_setup (void)
g_private_set (&task_private, GUINT_TO_POINTER (TRUE));
g_mutex_lock (&task_pool_mutex);
......@@ -1270,6 +1273,7 @@ g_task_thread_cleanup (void)
g_mutex_unlock (&task_pool_mutex);
g_private_set (&task_private, GUINT_TO_POINTER (FALSE));
static void
......@@ -1359,6 +1363,8 @@ g_task_start_task_thread (GTask *task,
task_thread_cancelled_disconnect_notify, 0);
if (g_private_get (&task_private))
task->blocking_other_task = TRUE;
g_thread_pool_push (task_pool, g_object_ref (task), NULL);
......@@ -1849,6 +1855,14 @@ g_task_compare_priority (gconstpointer a,
const GTask *tb = b;
gboolean a_cancelled, b_cancelled;
/* Tasks that are causing other tasks to block have higher
* priority.
if (ta->blocking_other_task && !tb->blocking_other_task)
return -1;
else if (tb->blocking_other_task && !ta->blocking_other_task)
return 1;
/* Let already-cancelled tasks finish right away */
a_cancelled = (ta->check_cancellable &&
g_cancellable_is_cancelled (ta->cancellable));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment