
#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.
 */
static int libsaria_queue_task_generic(IdleTask *task, bool front)
{
	int queue_size = idle.queue_task(task, front);
	if (queue_size == 1)
		trigger_callback(IDLE_TASK_QUEUED);
	return queue_size;
}

int libsaria_queue_task(IdleTask *task)
{
	return libsaria_queue_task_generic(task, false);
}

int libsaria_queue_task_front(IdleTask *task)
{
	return libsaria_queue_task_generic(task, true);
}
