Skip to main content

Module fiber

Module fiber 

Source
Expand description

Stackful fibers for blocking DPI import tasks (LRM 1800-2023 35.5.3, 35.7, 35.9).

A DPI import task is a C function that may call an exported SV task which consumes time. The C frame cannot be unwound into a stackless process state machine, so the call runs on a Fiber: a private stack the scheduler can leave (yield_now, from inside the fiber) and later re-enter (Fiber::resume). A call that never blocks finishes on its first resume and costs one stack switch pair.

Built on glibc’s makecontext/swapcontext (declared here directly: no libc dependency in this workspace). ucontext_t is kept as an opaque, over-sized buffer; the only fields touched go through those functions, except uc_stack / uc_link, which are located by the x86_64 / aarch64 glibc layout checked in the tests.

A panic never crosses the fiber boundary: the entry closure runs under catch_unwind and the payload is re-raised by Fiber::resume on the resuming stack.

Structs§

Fiber
One suspendable C call.

Enums§

FiberState
Whether a Fiber::resume left the fiber parked or ran it to its end.

Functions§

on_fiber
Whether the caller runs on a fiber (a blocking export is legal here).
yield_now
Parks the running fiber and returns to its resumer. false (nothing happened) when called on the main stack.