pub struct Tcb {Show 17 fields
pub sp: AtomicUsize,
pub base_priority: AtomicU8,
pub effective_priority: AtomicU8,
pub state: AtomicU8,
pub used: AtomicBool,
pub stack_base: AtomicUsize,
pub stack_size: AtomicUsize,
pub held: [HeldMutex; 4],
pub held_count: AtomicU8,
pub last_checkin: AtomicU32,
pub generation: AtomicU32,
pub result_buf: UnsafeCell<[u8; 32]>,
pub result_size: AtomicU8,
pub result_drop: AtomicUsize,
pub exited: AtomicBool,
pub joiner: AtomicUsize,
pub stop_requested: AtomicBool,
}Expand description
Task Control Block. One per preemptive task, held in the static registry.
Fields§
§sp: AtomicUsizeSaved stack pointer. Valid only while the task is not running.
base_priority: AtomicU8Priority as declared by the task (0 = lowest, 31 = highest).
effective_priority: AtomicU8Priority currently in effect. Normally equals base_priority;
temporarily boosted by crate::preempt::mutex::PriorityMutex to
the priority of whichever higher-priority task is blocked waiting
on a resource this task holds (priority inheritance — prevents
priority inversion).
state: AtomicU8Current scheduling state.
used: AtomicBoolWhether this slot holds a live task.
stack_base: AtomicUsizeStack base address (low end) and size in bytes, recorded at spawn. Used by the CM3 MPU per-switch stack region, RISC-V PMP guard attribution, and stack watermarking (plan.md §3).
stack_size: AtomicUsize§held: [HeldMutex; 4]Intrusive list of mutexes this task currently holds, for correct nested priority-inheritance recomputation on unlock (plan.md [B11]).
held_count: AtomicU8§last_checkin: AtomicU32Last task-level watchdog checkin time (µs, low 32 bits); 0 = never checked in (plan.md §3.5).
generation: AtomicU32Slot generation counter, incremented on every register (slot
reuse). Lets TaskHandle-based APIs detect a stale handle (ABA on
slot recycling, plan.md §5.1).
result_buf: UnsafeCell<[u8; 32]>Type-erased return value storage (plan.md §5.2): result_size bytes
of result_buf, written exactly once by rivet_task_exit before
exited is published. Read via TaskHandle::join.
result_size: AtomicU8§result_drop: AtomicUsizeType-erased drop_in_place for the stored result (0 = no-op).
exited: AtomicBoolSet by rivet_task_exit when the task’s entry returned.
joiner: AtomicUsizeId of the task blocked in join() on this task (or NO_TASK).
stop_requested: AtomicBoolCooperative cancellation flag (plan.md §5.4): set by
TaskHandle::request_stop, polled by should_stop().
Implementations§
Source§impl Tcb
impl Tcb
Sourcepub fn stack_info(&self) -> Option<(usize, usize)>
pub fn stack_info(&self) -> Option<(usize, usize)>
The task’s stack allocation (base, size) from the pool (0,0 if
none — host fallback stacks).
pub const fn new() -> Self
Sourcepub fn push_held(&self, ptr: *const (), hwp: fn(*const ()) -> u8) -> bool
pub fn push_held(&self, ptr: *const (), hwp: fn(*const ()) -> u8) -> bool
Record a mutex in this task’s held list. Returns false if the list
is full (MAX_HELD).
Sourcepub fn remove_held(&self, ptr: *const ())
pub fn remove_held(&self, ptr: *const ())
Remove a mutex from this task’s held list (no-op if absent).
pub fn state(&self) -> TaskState
Sourcepub fn set_state(&self, id: usize, s: TaskState)
pub fn set_state(&self, id: usize, s: TaskState)
Set the scheduling state and keep the O(1) scheduler’s ready queues consistent (plan.md §4.2): Ready tasks are queued at their effective priority; Running/Blocked tasks are not queued.
Sourcepub fn set_effective_priority(&self, id: usize, new: u8)
pub fn set_effective_priority(&self, id: usize, new: u8)
Set the effective priority (priority inheritance) and move the task between ready queues if it is currently Ready (plan.md §4.2).