File syn_sched.c¶
FileList > sched > syn_sched.c
Go to the source code of this file
Cooperative scheduler implementation.
#include "../port/syn_port_system.h"#include "../util/syn_assert.h"#include "../util/syn_event.h"#include "../util/syn_metrics.h"#include "syn_sched.h"#include <limits.h>
Public Functions¶
| Type | Name |
|---|---|
| size_t | syn_sched_alive_count (const SYN_Sched * sched) Get the number of tasks that are still alive in the scheduler. |
| void | syn_sched_init (SYN_Sched * sched, SYN_Task * tasks, size_t count) Initialize the scheduler with a task array. |
| bool | syn_sched_run (SYN_Sched * sched) Run one scheduler tick. |
| SYN_NORETURN void | syn_sched_run_forever (SYN_Sched * sched) Run the scheduler forever. |
| void | syn_task_create (SYN_Task * task, const char * name, SYN_TaskFunc func, uint8_t priority, void * user_data) Initialize a single task descriptor. |
| void | syn_task_restart (SYN_Task * task) Restart a task from the beginning of its protothread. |
| void | syn_task_resume (SYN_Task * task) Resume a suspended task, making it eligible to run again. |
| void | syn_task_suspend (SYN_Task * task) Suspend a task. It will be skipped by the scheduler until resumed. |
Public Static Functions¶
| Type | Name |
|---|---|
| SYN_PT_Status | sched_run_task (SYN_Task * task) Execute a single task's protothread function. |
Public Functions Documentation¶
function syn_sched_alive_count¶
Get the number of tasks that are still alive in the scheduler.
Parameters:
schedScheduler.
Returns:
Alive task count.
function syn_sched_init¶
Initialize the scheduler with a task array.
Parameters:
schedScheduler to initialize.tasksPointer to an array of SYN_Task structs. Each task should already be initialized via syn_task_create().countNumber of tasks in the array.
function syn_sched_run¶
Run one scheduler tick.
Scans all tasks and runs the single highest-priority ready task (lowest priority value first, round-robin among equal priorities).
Parameters:
schedScheduler to run.
Returns:
true if at least one task is still alive (not DEAD).
function syn_sched_run_forever¶
Run the scheduler forever.
Equivalent to while (1) { syn_sched_run(sched); }. This function never returns.
Parameters:
schedScheduler to run.
function syn_task_create¶
Initialize a single task descriptor.
void syn_task_create (
SYN_Task * task,
const char * name,
SYN_TaskFunc func,
uint8_t priority,
void * user_data
)
Sets the task to READY state with the protothread reset to the top.
Parameters:
taskTask to initialize.nameHuman-readable name (stored by pointer, not copied).funcProtothread function.priorityPriority level (0 = highest).user_dataOptional pointer to task-private data (or NULL).
function syn_task_restart¶
Restart a task from the beginning of its protothread.
Resets the protothread continuation and sets the task to READY.
Parameters:
taskTask to restart.
function syn_task_resume¶
Resume a suspended task, making it eligible to run again.
Parameters:
taskTask to resume.
function syn_task_suspend¶
Suspend a task. It will be skipped by the scheduler until resumed.
Parameters:
taskTask to suspend.
Public Static Functions Documentation¶
function sched_run_task¶
Execute a single task's protothread function.
Parameters:
taskTask to run.
Returns:
The protothread status returned by the task.
The documentation for this class was generated from the following file src/syntropic/sched/syn_sched.c