Revert "GIOScheduler: Avoid constant iteration over pending job list"
This reverts commit 2839297686a9305b4fa909b93c337ef1d1a5e94b.
Conflicts:
gio/gioscheduler.c
https://bugzilla.gnome.org/show_bug.cgi?id=678576
diff --git a/gio/gioscheduler.c b/gio/gioscheduler.c
index f3e629c..b94d8dd 100644
--- a/gio/gioscheduler.c
+++ b/gio/gioscheduler.c
@@ -120,17 +120,34 @@
}
static void
-on_job_canceled (GCancellable *cancellable,
- gpointer user_data)
+remove_active_job (GIOSchedulerJob *job)
{
- GIOSchedulerJob *job = user_data;
-
- job->io_priority = -1;
-
- if (job_thread_pool != NULL)
+ GIOSchedulerJob *other_job;
+ GList *l;
+ gboolean resort_jobs;
+
+ G_LOCK (active_jobs);
+ active_jobs = g_list_delete_link (active_jobs, job->active_link);
+
+ resort_jobs = FALSE;
+ for (l = active_jobs; l != NULL; l = l->next)
+ {
+ other_job = l->data;
+ if (other_job->io_priority >= 0 &&
+ g_cancellable_is_cancelled (other_job->cancellable))
+ {
+ other_job->io_priority = -1;
+ resort_jobs = TRUE;
+ }
+ }
+ G_UNLOCK (active_jobs);
+
+ if (resort_jobs &&
+ job_thread_pool != NULL)
g_thread_pool_set_sort_function (job_thread_pool,
g_io_job_compare,
NULL);
+
}
static void
@@ -141,9 +158,7 @@
if (job->destroy_notify)
job->destroy_notify (job->data);
- G_LOCK (active_jobs);
- active_jobs = g_list_delete_link (active_jobs, job->active_link);
- G_UNLOCK (active_jobs);
+ remove_active_job (job);
g_io_job_free (job);
}
@@ -206,11 +221,7 @@
job->io_priority = io_priority;
if (cancellable)
- {
- job->cancellable = g_object_ref (cancellable);
- g_cancellable_connect (job->cancellable, (GCallback)on_job_canceled,
- job, NULL);
- }
+ job->cancellable = g_object_ref (cancellable);
job->context = g_main_context_ref_thread_default ();