Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
srn_fiber_t Struct Reference

#include <fiber.h>

Collaboration diagram for srn_fiber_t:
[legend]

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_tctx
 
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_tlink
 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_twaiters
 Head of the list of fibers blocked in srn_fiber_wait_for on this fiber.
 
srn_fiber_treg_prev
 Registry links.
 
srn_fiber_treg_next
 
const char * name
 For debugging purposes.
 

Detailed Description

Definition at line 208 of file fiber.h.

Field Documentation

◆ arg

void* srn_fiber_t::arg

Definition at line 220 of file fiber.h.

◆ ctx

srn_context_t* srn_fiber_t::ctx

Definition at line 218 of file fiber.h.

◆ entry

srn_fiber_entry_t srn_fiber_t::entry

Definition at line 219 of file fiber.h.

◆ fiber_ctx

srn_fiber_ctx_t srn_fiber_t::fiber_ctx

Saved stack pointer (see srn_fiber_ctx_t)

Definition at line 210 of file fiber.h.

◆ link

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.

Definition at line 247 of file fiber.h.

◆ name

const char* srn_fiber_t::name

For debugging purposes.

Definition at line 270 of file fiber.h.

◆ park_arg

void* srn_fiber_t::park_arg

Definition at line 229 of file fiber.h.

◆ park_commit

srn_fiber_park_fn srn_fiber_t::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).

Valid only across that one suspend hand-off.

Definition at line 228 of file fiber.h.

◆ reg_next

srn_fiber_t* srn_fiber_t::reg_next

Definition at line 267 of file fiber.h.

◆ reg_prev

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).

Definition at line 266 of file fiber.h.

◆ result

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.

Definition at line 223 of file fiber.h.

◆ stack

srn_fiber_stack_t srn_fiber_t::stack

Definition at line 211 of file fiber.h.

◆ state

_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.

Definition at line 217 of file fiber.h.

◆ waiters

srn_fiber_t* srn_fiber_t::waiters

Head of the list of fibers blocked in srn_fiber_wait_for on this fiber.

They are threaded through their own link (a waiter is suspended, so off the ready queue, and its link is free). When this fiber reaches DONE the worker routine wakes them all.

Definition at line 253 of file fiber.h.


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