Skip to main content

Tcb

Struct Tcb 

Source
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: AtomicUsize

Saved stack pointer. Valid only while the task is not running.

§base_priority: AtomicU8

Priority as declared by the task (0 = lowest, 31 = highest).

§effective_priority: AtomicU8

Priority 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: AtomicU8

Current scheduling state.

§used: AtomicBool

Whether this slot holds a live task.

§stack_base: AtomicUsize

Stack 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: AtomicU32

Last task-level watchdog checkin time (µs, low 32 bits); 0 = never checked in (plan.md §3.5).

§generation: AtomicU32

Slot 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: AtomicUsize

Type-erased drop_in_place for the stored result (0 = no-op).

§exited: AtomicBool

Set by rivet_task_exit when the task’s entry returned.

§joiner: AtomicUsize

Id of the task blocked in join() on this task (or NO_TASK).

§stop_requested: AtomicBool

Cooperative cancellation flag (plan.md §5.4): set by TaskHandle::request_stop, polled by should_stop().

Implementations§

Source§

impl Tcb

Source

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

Source

pub const fn new() -> Self

Source

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

Source

pub fn remove_held(&self, ptr: *const ())

Remove a mutex from this task’s held list (no-op if absent).

Source

pub fn state(&self) -> TaskState

Source

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.

Source

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

Trait Implementations§

Source§

impl Default for Tcb

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Sync for Tcb

Auto Trait Implementations§

§

impl !Freeze for Tcb

§

impl !RefUnwindSafe for Tcb

§

impl Send for Tcb

§

impl Unpin for Tcb

§

impl UnsafeUnpin for Tcb

§

impl UnwindSafe for Tcb

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.