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 <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
df21aa1299
commit
2a95031ee7
22
core/idle.c
22
core/idle.c
|
@ -8,7 +8,6 @@
|
||||||
struct idle_task {
|
struct idle_task {
|
||||||
bool (*idle_func)(void *);
|
bool (*idle_func)(void *);
|
||||||
void *idle_data;
|
void *idle_data;
|
||||||
enum idle_sync_t idle_sync;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static GThreadPool *idle_pool = NULL;
|
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)
|
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_func = func;
|
||||||
task->idle_data = data;
|
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);
|
g_atomic_int_inc(&queued);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +84,7 @@ bool idle_run_task()
|
||||||
|
|
||||||
if (!g_queue_is_empty(&idle_queue)) {
|
if (!g_queue_is_empty(&idle_queue)) {
|
||||||
task = g_queue_pop_head(&idle_queue);
|
task = g_queue_pop_head(&idle_queue);
|
||||||
if (task->idle_sync == IDLE_ASYNC) {
|
if (!__idle_run_task(task))
|
||||||
if (idle_pool)
|
|
||||||
g_thread_pool_push(idle_pool, task, NULL);
|
|
||||||
else
|
|
||||||
__idle_free_task(task);
|
|
||||||
} else if (!__idle_run_task(task))
|
|
||||||
g_queue_push_tail(&idle_queue, task);
|
g_queue_push_tail(&idle_queue, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue