ocarina/libsaria/idle.cpp
Bryan Schumaker 59fbd0c696 libsaria: Notify UI when the idle queue size has changed
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.
2011-09-13 17:27:46 -04:00

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;
}