These functions implement the underlying architecture specific operations to initialize, start, yield, and end fibers. These can be used to implement an alternative scheduling strategy or use fibers outside of modm.
void modm_noreturn modm_context_end |
( |
uintptr_t |
retval | ) |
|
Switches control from the fiber context back to the main context. Control flow then continues in the main context by returning from the modm_context_start()
function.
void modm_context_init |
( |
modm_context_t * |
ctx, |
|
|
uintptr_t * |
bottom, |
|
|
uintptr_t * |
top, |
|
|
uintptr_t |
fn, |
|
|
uintptr_t |
arg |
|
) |
| |
Initializes the context with the function pointer and argument stored at the top. The ctx->sp
is set to two uintptr_t
below the top. Must be called only once to initialize the stack.
- Parameters
-
fn | function pointer to a void(*)(uintptr_t) function. |
Pushes the context onto the from->sp
and pops the context from the to->sp
to jump from one fiber to the next.
Resets the context stack pointer to the correct offset in preparation for jumping into the fiber. Must be called after initialization, but every time the function is started from the beginning.
Returns the stack usage by searching from the bottom of the stack for the watermark level. You may call this function at any point after calling modm_context_stack_watermark()
.
Zeros the register file and watermarks the rest of the stack. You may call this function before or after modm_context_reset()
, however, NOT while the fiber is running!
Switches control from the main context to the fiber context. This initializes the hardware and then jumps from the caller context into the to
fiber.