Skip to content

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.

size_t syn_sched_alive_count (
    const SYN_Sched * sched
) 

Parameters:

  • sched Scheduler.

Returns:

Alive task count.


function syn_sched_init

Initialize the scheduler with a task array.

void syn_sched_init (
    SYN_Sched * sched,
    SYN_Task * tasks,
    size_t count
) 

Parameters:

  • sched Scheduler to initialize.
  • tasks Pointer to an array of SYN_Task structs. Each task should already be initialized via syn_task_create().
  • count Number of tasks in the array.

function syn_sched_run

Run one scheduler tick.

bool syn_sched_run (
    SYN_Sched * sched
) 

Scans all tasks and runs the single highest-priority ready task (lowest priority value first, round-robin among equal priorities).

Parameters:

  • sched Scheduler to run.

Returns:

true if at least one task is still alive (not DEAD).


function syn_sched_run_forever

Run the scheduler forever.

SYN_NORETURN void syn_sched_run_forever (
    SYN_Sched * sched
) 

Equivalent to while (1) { syn_sched_run(sched); }. This function never returns.

Parameters:

  • sched Scheduler 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:

  • task Task to initialize.
  • name Human-readable name (stored by pointer, not copied).
  • func Protothread function.
  • priority Priority level (0 = highest).
  • user_data Optional pointer to task-private data (or NULL).

function syn_task_restart

Restart a task from the beginning of its protothread.

void syn_task_restart (
    SYN_Task * task
) 

Resets the protothread continuation and sets the task to READY.

Parameters:

  • task Task to restart.

function syn_task_resume

Resume a suspended task, making it eligible to run again.

void syn_task_resume (
    SYN_Task * task
) 

Parameters:

  • task Task to resume.

function syn_task_suspend

Suspend a task. It will be skipped by the scheduler until resumed.

void syn_task_suspend (
    SYN_Task * task
) 

Parameters:

  • task Task to suspend.

Public Static Functions Documentation

function sched_run_task

Execute a single task's protothread function.

static SYN_PT_Status sched_run_task (
    SYN_Task * task
) 

Parameters:

  • task Task 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