2015-11-10 14:18:11 -05:00
|
|
|
/*
|
2013-09-01 10:55:13 -04:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
2015-11-10 13:52:24 -05:00
|
|
|
*
|
2014-11-08 11:55:22 -05:00
|
|
|
* The idle queue is used to schedule function calls to run at a
|
|
|
|
* later time. It is expected that a higher layer can determine
|
2015-11-10 13:52:24 -05:00
|
|
|
* when the application is idle and call idle_run_task() accordingly.
|
2014-11-08 11:55:22 -05:00
|
|
|
*
|
|
|
|
* 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.
|
2014-10-17 09:56:54 -04:00
|
|
|
*/
|
2015-11-10 13:52:24 -05:00
|
|
|
#ifndef OCARINA_CORE_IDLE_H
|
|
|
|
#define OCARINA_CORE_IDLE_H
|
2015-11-10 14:18:11 -05:00
|
|
|
#include <stdbool.h>
|
2013-09-01 10:55:13 -04:00
|
|
|
|
2016-04-30 09:16:02 -04:00
|
|
|
enum idle_sync_t {
|
|
|
|
IDLE_SYNC, /* Run task in the main thread. */
|
2016-04-30 10:11:48 -04:00
|
|
|
IDLE_ASYNC, /* Run task in a separate thread. */
|
2016-04-30 09:16:02 -04:00
|
|
|
};
|
|
|
|
|
2016-05-02 18:42:38 -04:00
|
|
|
#define IDLE_FUNC(x) ((bool (*)(void *))x)
|
2016-04-30 09:16:02 -04:00
|
|
|
|
2016-04-30 10:11:48 -04:00
|
|
|
|
|
|
|
/* Called to initialize the idle queue. */
|
|
|
|
void idle_init();
|
2016-07-28 16:15:29 -04:00
|
|
|
#ifdef CONFIG_TESTING
|
|
|
|
void idle_init_sync();
|
|
|
|
#endif /* CONFIG_TESTING */
|
2016-04-30 10:11:48 -04:00
|
|
|
|
|
|
|
/* Called to deinitialize the idle queue. */
|
|
|
|
void idle_deinit();
|
|
|
|
|
2015-11-10 13:52:24 -05:00
|
|
|
/* Called to schedule a function to run later. */
|
2016-05-02 18:42:38 -04:00
|
|
|
void idle_schedule(enum idle_sync_t, bool (*)(void *), void *);
|
2015-11-10 13:27:32 -05:00
|
|
|
|
2015-11-10 13:56:54 -05:00
|
|
|
/*
|
|
|
|
* Called to run the next task on the idle queue.
|
|
|
|
* Returns true if there are more tasks to run.
|
|
|
|
*/
|
|
|
|
bool idle_run_task();
|
|
|
|
|
2015-11-10 13:27:32 -05:00
|
|
|
/* Called to find the percentage of idle tasks that have been run. */
|
|
|
|
float idle_progress();
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_IDLE_H */
|