- if (job->cancellable)
- g_object_unref (job->cancellable);
- if (job->context)
- g_main_context_unref (job->context);
- g_free (job);
-}
-
-static gint
-g_io_job_compare (gconstpointer a,
- gconstpointer b,
- gpointer user_data)
-{
- const GIOSchedulerJob *aa = a;
- const GIOSchedulerJob *bb = b;
-
- /* Cancelled jobs are set prio == -1, so that
- they are executed as quickly as possible */
-
- /* Lower value => higher priority */
- if (aa->io_priority < bb->io_priority)
- return -1;
- if (aa->io_priority == bb->io_priority)
- return 0;
- return 1;
-}
-
-static gpointer
-init_scheduler (gpointer arg)
-{
- if (job_thread_pool == NULL)
- {
- /* TODO: thread_pool_new can fail */
- job_thread_pool = g_thread_pool_new (io_job_thread,
- NULL,
- 10,
- FALSE,
- NULL);
- if (job_thread_pool != NULL)
- {
- g_thread_pool_set_sort_function (job_thread_pool,
- g_io_job_compare,
- NULL);
- /* It's kinda weird that this is a global setting
- * instead of per threadpool. However, we really
- * want to cache some threads, but not keep around
- * those threads forever. */
- g_thread_pool_set_max_idle_time (15 * 1000);
- g_thread_pool_set_max_unused_threads (2);
- }
- }
- return NULL;
-}