Skip to main content

TickCell

Struct TickCell 

Source
pub struct TickCell { /* private fields */ }
Expand description

A shared, coarsely-updated tick count — the common per-core/per-shard “what time is it, roughly” cell, distinct from a per-read hardware register.

Some deployments do not want every caller reading a hardware counter directly (a syscall-backed clock, a register behind a slow bus, a counter shared across cores where every core hitting the same cache line would thrash it). The usual answer is one owner reads the real source occasionally and writes the result here; every other reader reads this cell instead — cheap, lock-free, and no less accurate than the owner’s update cadence.

TickCell reads exactly like a hardware counter: impl Pipe for &TickCell gives it the same In = (), Out = Ticks, Err = Infallible source shape as a read_volatile on a memory-mapped register (see tests/hardware_mmap_seam.rs, which drives both through one pipeline) — a caller composing a pipeline does not know or care whether a given tick source is a raw register or this cell.

Deliberately NOT a process-wide static here: how a cell is reached (a field on a per-core context, threaded through a runtime handle, a static a caller chooses to declare) is a runtime-wiring decision this no_std leaf crate does not make on the caller’s behalf.

§Contract

Single writer: TickCell::set is for the one owner that reads the real source and republishes it. Concurrent set calls from more than one caller are not synchronized against each other — the underlying seqlock’s odd/even bump is not itself compare-and-swapped. Any number of readers may call TickCell::get (or drive it as a Pipe) concurrently, lock-free.

Implementations§

Source§

impl TickCell

Source

pub fn new(initial: Ticks) -> Self

Construct a cell starting at initial.

Source

pub fn set(&self, ticks: Ticks)

Republish the current tick count. See the struct doc’s single-writer contract.

Source

pub fn get(&self) -> Ticks

Read the current tick count.

Trait Implementations§

Source§

impl Debug for TickCell

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pipe for &TickCell

Source§

type In = ()

Input the pipe consumes.
Source§

type Out = Ticks

Output the pipe produces.
Source§

type Err = !

Error the pipe can fail with. Debug + 'static; Send is added only on the cross-core SendPipe form.
Source§

fn call(&self, (): ()) -> impl Future<Output = Result<Ticks, Infallible>>

Apply the pipe. The returned future is NOT required to be Send.

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.