|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
#include "serene/rt/fiber.h"#include "serene/rt/context.h"#include "serene/utils.h"#include <string.h>Go to the source code of this file.
Functions | |
| void | srn_fiber_switch (srn_fiber_t *from, srn_fiber_t *to) |
Compiled without AddressSanitizer instrumentation: in stack-use-after-return mode ASan would place from/to on a fake stack that __sanitizer_start_switch_fiber releases before srn_fiber_swap reads them. | |
| void | srn_fiber_switch_final (srn_fiber_t *to) |
Like srn_fiber_switch, but for a fiber that has finished and must not be resumed: control transfers to to and never comes back. | |
| void | srn_fiber_on_entry (srn_fiber_t *from) |
| Call as the first action inside a fresh fiber's entry. | |
| void | srn_fiber_on_reap (srn_fiber_t *fiber) |
| Call when a finished fiber is reaped, after it has switched away for the last time. | |
| void | srn_fiber_init_thread (srn_fiber_t *f) |
| Represent the calling OS thread as the running fiber ("#0"), so the scheduler or a test can switch away from it and back. | |
| static void | srn_fiber_launcher (void *fiber_ptr) |
| srn_fiber_t * | srn_fiber_make (srn_context_t *ctx, srn_scheduler_t *sched, srn_fiber_entry_t entry, void *arg, size_t stack_size) |
| Create a fiber that will run entry(ctx, arg). | |
| void srn_fiber_init_thread | ( | srn_fiber_t * | f | ) |
Represent the calling OS thread as the running fiber ("#0"), so the scheduler or a test can switch away from it and back.
The thread's stack bounds are not queried here (there is no portable way). Under the sanitizer they are recorded by the first fiber's srn_fiber_on_entry. The saved context is written by the first switch away.
Definition at line 137 of file fiber.c.
|
static |
Definition at line 152 of file fiber.c.
|
nodiscard |
Create a fiber that will run entry(ctx, arg).
The fiber allocates into its block and never releases it. A stack_size of 0 selects SRN_FIBER_DEFAULT_STACK_SIZE.
Definition at line 169 of file fiber.c.
| void srn_fiber_on_entry | ( | srn_fiber_t * | from | ) |
Call as the first action inside a fresh fiber's entry.
from is the fiber that started this one (the scheduler, or the bootstrap thread fiber). It completes the switch for AddressSanitizer and, since from's stack bounds only become discoverable here, records them into from so a later switch back is tracked. from may be null. A no-op when the sanitizer is not in use.
Definition at line 107 of file fiber.c.
| void srn_fiber_on_reap | ( | srn_fiber_t * | fiber | ) |
Call when a finished fiber is reaped, after it has switched away for the last time.
Releases the fiber's ThreadSanitizer handle. A no-op when the sanitizer is not in use.
Definition at line 129 of file fiber.c.
| void srn_fiber_switch | ( | srn_fiber_t * | from, |
| srn_fiber_t * | to ) |
Compiled without AddressSanitizer instrumentation: in stack-use-after-return mode ASan would place from/to on a fake stack that __sanitizer_start_switch_fiber releases before srn_fiber_swap reads them.
Switch from from to to, both live fibers, telling AddressSanitizer about the stack change.
Not instrumented by either sanitizer: the stack swaps mid-function, which confuses ASan's fake stack and TSan's shadow stack. The explicit annotations keep each sanitizer's fiber tracking correct across the swap instead.
Definition at line 62 of file fiber.c.
| void srn_fiber_switch_final | ( | srn_fiber_t * | to | ) |
Like srn_fiber_switch, but for a fiber that has finished and must not be resumed: control transfers to to and never comes back.
The fiber's entry function therefore ends at this call – any code after it is unreachable, which is why this is [[noreturn]]. Nothing is freed here. The spent fiber's stack is left frozen and reclaimed later by its owner (the scheduler reaps a finished fiber and frees its stack via srn_fiber_stack_free).
Definition at line 85 of file fiber.c.