|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
#include <fiber.h>
Data Fields | |
| srn_fiber_ctx_t | fiber_ctx |
| Saved stack pointer (see srn_fiber_ctx_t) | |
| srn_fiber_stack_t | stack |
| _Atomic srn_fiber_state_t | state |
| The lifecycle state. | |
| srn_context_t * | ctx |
| srn_fiber_entry_t | entry |
| void * | arg |
| srn_fiber_result_t | result |
| Set when state reaches SRN_FIBER_DONE. | |
| srn_fiber_park_fn | park_commit |
| While this fiber is suspending, the commit the worker routine runs once the fiber is off the stack, to publish it to its waker (see srn_fiber_suspend). | |
| void * | park_arg |
| srn_fiber_t * | link |
| Intrusive link threading this fiber onto one of the scheduler's singly-linked lists (the ready run queue, or a wait queue) without a separate node allocation: the next pointer lives in the fiber itself. | |
| srn_fiber_t * | waiters |
| Head of the list of fibers blocked in srn_fiber_wait_for on this fiber. | |
| srn_fiber_t * | reg_prev |
| Registry links. | |
| srn_fiber_t * | reg_next |
| const char * | name |
| For debugging purposes. | |
| srn_context_t* srn_fiber_t::ctx |
| srn_fiber_entry_t srn_fiber_t::entry |
| srn_fiber_ctx_t srn_fiber_t::fiber_ctx |
Saved stack pointer (see srn_fiber_ctx_t)
| srn_fiber_t* srn_fiber_t::link |
Intrusive link threading this fiber onto one of the scheduler's singly-linked lists (the ready run queue, or a wait queue) without a separate node allocation: the next pointer lives in the fiber itself.
A fiber belongs to at most one such list at a time, so one link suffices.
| srn_fiber_park_fn srn_fiber_t::park_commit |
| srn_fiber_t* srn_fiber_t::reg_next |
| srn_fiber_t* srn_fiber_t::reg_prev |
Registry links.
The scheduler keeps every live fiber on one doubly linked list through these pointers. It is different from link. link says where a fiber sits in the run order, the registry says the fiber exists at all. A fiber joins the list when it is created and leaves when it is reaped, in whatever state it is in between – including SUSPENDED, which sits on no queue.
This is how the scheduler accounts for, cleans up, and (later) cancels its fibers. Doubly linked so reaping can unlink from the middle in O(1).
| srn_fiber_result_t srn_fiber_t::result |
Set when state reaches SRN_FIBER_DONE.
Type-erased (see srn_fiber_result_t), the caller interprets it.
| srn_fiber_stack_t srn_fiber_t::stack |
| _Atomic srn_fiber_state_t srn_fiber_t::state |
The lifecycle state.
Atomic because a waker may run on a different os thread than the worker running the fiber. srn_fiber_ready flips SUSPENDED to READY with a CAS while the worker running the fiber reads and writes the same field. Making it atomic keeps every access whole, so a read can never see an inconsistent value.
| srn_fiber_t* srn_fiber_t::waiters |