modm API documentation
modm::fiber::Scheduler Class Reference

#include <modm/processing/fiber/scheduler.hpp>

Static Public Member Functions

static void run ()
 Runs the currently active scheduler.
 

Protected Member Functions

void runNext (Task *task)
 
void runLast (Task *task)
 
TaskremoveCurrent ()
 
bool empty () const
 
void jump (Task &other)
 
void yield ()
 
void unschedule ()
 
void add (Task &task)
 
bool start ()
 

Static Protected Member Functions

static Scheduler & instance ()
 Returns the currently active scheduler.
 

Protected Attributes

Tasklast {nullptr}
 
Taskcurrent {nullptr}
 

Friends

class Task
 
void yield ()
 

Detailed Description

The scheduler executes fibers in a simple round-robin fashion. Fibers can be added to a scheduler using the modm::fiber::Task::start() function, also while the scheduler is running. Fibers returning from their function will automatically unschedule themselves.

Friends And Related Function Documentation

void yield ( )
friend

Calls into the currently active scheduler to jump to the next fiber. Local control flow resumes by returning from this function.

Note
If called while no scheduler is active, or only one fiber is currently running, this function returns immediately without performing a jump. This can cause deadlocks if the calling fiber waits on progress made outside of it.
Warning
Be careful to yield inside long running loops or when busy-waiting. These are cooperative fibers, so the scheduler will not preempt fibers, and you may starve other fibers of processing time. If you cannot guarantee correct timings, consider using an RTOS.

The documentation for this class was generated from the following file: