ocarina/include/core/idle.h
Anna Schumaker 8c8ab2a9eb core/idle: Add idle_cancel() function
This function is used to cancel all idle tasks and free the memory
allocated for them.  This needs to be called when Ocarina is shutting
down to prevent a possible hang with the gtk idle callback continuing to
process tasks.

Fixes #30: Closing Ocarina should cancel idle tasks
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
2016-03-01 08:27:13 -05:00

34 lines
1.0 KiB
C

/*
* Copyright 2013 (c) Anna Schumaker.
*
* The idle queue is used to schedule function calls to run at a
* later time. It is expected that a higher layer can determine
* when the application is idle and call idle_run_task() accordingly.
*
* The idle layer keeps a count of the number of tasks added to the queue
* since the last time the queue was empty. Whenever a task is scheduled,
* the "queued" count is incremented by 1. When tasks are run, the "serviced"
* count is incremented by 1. These counters are reset to 0 once the queue
* is empty.
*/
#ifndef OCARINA_CORE_IDLE_H
#define OCARINA_CORE_IDLE_H
#include <stdbool.h>
/* Called to schedule a function to run later. */
void idle_schedule(void (*)(void *), void *);
/*
* Called to run the next task on the idle queue.
* Returns true if there are more tasks to run.
*/
bool idle_run_task();
/* Called to find the percentage of idle tasks that have been run. */
float idle_progress();
/* Called to cancel all idle tasks on the queue. */
void idle_cancel();
#endif /* OCARINA_CORE_IDLE_H */