File round_robin.h
A basic round-robin scheduler.
Defines
-
SCHEDULER_MAX_EXTERNAL_EVENT_COUNT
Maximum number of external events a scheduler can handle between each yield.
Typedefs
-
typedef struct round_robin_scheduler RoundRobinScheduler
Functions
-
Scheduler *round_robin_scheduler_create(Coro *const *coro_list, size_t num_coros)
Create a basic scheduler.
- Parameters:
coro_list – List of coroutines to schedule.
num_coros – Number of coroutines in the list.
- Returns:
Pointer to the scheduler, or NULL on error.
-
Scheduler *round_robin_scheduler_create_static(RoundRobinScheduler *scheduler, Coro **coro_list, size_t num_coros)
-
void round_round_robin_scheduler_free(RoundRobinScheduler *scheduler)
Frees a dynamically allocated scheduler.
- Parameters:
scheduler – Scheduler to free, must have been created from round_robin_scheduler_create.
-
Result round_robin_scheduler_add_coro(RoundRobinScheduler *scheduler, Coro *coro)
Add a coroutine to the scheduler.
Note
This will only use empty slots. If a coroutine is finished, its slow must be explicitly cleared by the caller. This is to guarantee to the caller that the scheduler holds the reference (until being told not to).
- Parameters:
scheduler –
coro –
- Return values:
RES_OK – if the coroutine has been added
RES_NO_MEM – if there was no space for the coroutine
-
void round_robin_scheduler_remove_coro(RoundRobinScheduler *scheduler, Coro const *coro)
-
struct round_robin_scheduler
Public Members
-
size_t max_tasks_count
Maximum number of tasks the task array can store.
-
size_t all_tasks
Number of actual tasks in the task list.
-
size_t finished_tasks
-
size_t next_task_index
index to check next when performing a context switch
-
CoroEventSource external_events[SCHEDULER_MAX_EXTERNAL_EVENT_COUNT]
-
PlatformTick previous_ticks
-
size_t max_tasks_count