59fbd0c696
When the first task is queued, I trigger a callback so the UI can start processing when idle. I return the size of the queue from both run_task() and queue_task() so the UI knows when to stop processing callbacks.
28 lines
622 B
C++
28 lines
622 B
C++
|
|
#include <libsaria/callback.h>
|
|
#include "idle/idle.h"
|
|
|
|
static Idle idle;
|
|
|
|
int libsaria_idle_task()
|
|
{
|
|
return idle.run_task();
|
|
}
|
|
|
|
/*
|
|
* This will queue a pre-constructed idle task
|
|
* It should be constructed through `new` before calling
|
|
* and will be deleted by the idle queue once run.
|
|
*
|
|
* IDLE_TASK_QUEUED will only be triggered when the queue
|
|
* goes from size is increased from 0 to 1. This will tell
|
|
* the UI that idle tasks have been queued.
|
|
*/
|
|
int libsaria_queue_task(IdleTask *task)
|
|
{
|
|
int queue_size = idle.queue_task(task);
|
|
if (queue_size == 1)
|
|
trigger_callback(IDLE_TASK_QUEUED);
|
|
return queue_size;
|
|
}
|