/* * 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 enum idle_sync_t { IDLE_SYNC, /* Run task in the main thread. */ IDLE_ASYNC, /* Run task in a separate thread. */ }; #define IDLE_FUNC(x) ((bool (*)(void *))x) /* Called to initialize the idle queue. */ void idle_init(enum idle_sync_t); /* Called to deinitialize the idle queue. */ void idle_deinit(); /* Called to schedule a function to run later. */ void idle_schedule(enum idle_sync_t, bool (*)(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(); #endif /* OCARINA_CORE_IDLE_H */