From 2a95031ee71c11706fb0362ab017723310d3af51 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 29 Sep 2016 16:37:53 -0400 Subject: [PATCH] core/idle: Schedule async idle tasks directly Rather than processing them twice. This should speed things up a tiny bit. Signed-off-by: Anna Schumaker --- core/idle.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/idle.c b/core/idle.c index 6369f146..9c405384 100644 --- a/core/idle.c +++ b/core/idle.c @@ -8,7 +8,6 @@ struct idle_task { bool (*idle_func)(void *); void *idle_data; - enum idle_sync_t idle_sync; }; static GThreadPool *idle_pool = NULL; @@ -62,12 +61,20 @@ void idle_deinit() void idle_schedule(enum idle_sync_t sync, bool (*func)(void *), void *data) { - struct idle_task *task = g_malloc(sizeof(struct idle_task)); + struct idle_task *task; + + if (sync == IDLE_ASYNC && !idle_pool) + return; + + task = g_malloc(sizeof(struct idle_task)); task->idle_func = func; task->idle_data = data; - task->idle_sync = sync; - g_queue_push_tail(&idle_queue, task); + if (sync == IDLE_SYNC) + g_queue_push_tail(&idle_queue, task); + else + g_thread_pool_push(idle_pool, task, NULL); + g_atomic_int_inc(&queued); } @@ -77,12 +84,7 @@ bool idle_run_task() if (!g_queue_is_empty(&idle_queue)) { task = g_queue_pop_head(&idle_queue); - if (task->idle_sync == IDLE_ASYNC) { - if (idle_pool) - g_thread_pool_push(idle_pool, task, NULL); - else - __idle_free_task(task); - } else if (!__idle_run_task(task)) + if (!__idle_run_task(task)) g_queue_push_tail(&idle_queue, task); }