Skip to main content

SharedCellInner

Struct SharedCellInner 

Source
pub struct SharedCellInner {
    pub value: Mutex<Value>,
    pub revision: AtomicU64,
    pub scope_intent_dirty: Arc<AtomicU64>,
    pub bit: u8,
}
Expand description

A cross-kernel mutable cell for a shared-modifier wire.

When a shared output in an outer scope is bound into an inner kernel via materialize_wiring_from_outer, both kernels’ input slots reference the same SharedCell. Writes from inner via set_input flow through to the cell; reads on either side pick up the latest value.

Concurrent writers serialize at the Mutex; the current semantic is last-write-wins (lock-acquisition order). Future templated patterns (atomic-fetch-add, sum-reduction, merge, etc.) — see SRD-16 §“Open: concurrent shared mutation” — will introduce alternative cell types selected per binding declaration.

§Cross-fiber validity tracking

Each cell carries its own validity-tracking handles per polydat/docs/design/cross_fiber_invalidation.md:

  • revision: AtomicU64 — monotonic counter, bumped on every write. Consumer fibers cache the last revision they observed in their per-fiber last_seen map; a mismatch tells the cone walker to re-evaluate.
  • scope_intent_dirty: Arc<AtomicU64> — one intent word, shared with every other cell allocated from the same word. The cell’s bit position is set on every write, allowing consumers to do an O(1) bulk check (“any cell in this scope dirty?”) before drilling down to the per-cell revision compare.
  • bit: u8 — this cell’s position within its word. The scope keeps one Arc<AtomicU64> per 64 cells, grown on demand by the defining scope’s EngineCore::allocate_cell_bit.

The reader contract (S5 §1.1) is preserved: a producer’s publish writes value + revision + intent bit in three Release stores; a consumer’s check_clean walk on its next read observes the change without any host-side ceremony.

Fields§

§value: Mutex<Value>

Cell value. The mutex serialises concurrent writers and gives readers single-value atomicity.

§revision: AtomicU64

Monotonic revision counter. Bumped on every write (Release); compared by consumers (Acquire) against per-fiber last_seen.

§scope_intent_dirty: Arc<AtomicU64>

Defining scope’s intent-dirty bit-vector. Shared by Arc across every cell allocated by the same scope. On every write the producer ORs 1 << self.bit into this (Release) so consumers’ bulk-mask check sees the scope as dirty.

§bit: u8

This cell’s bit position in scope_intent_dirty. Stable for the cell’s lifetime.

Implementations§

Source§

impl SharedCellInner

Source

pub fn new(initial: Value, scope_intent_dirty: Arc<AtomicU64>, bit: u8) -> Self

Construct a new cell with the given initial value, bound to the defining scope’s intent-dirty word at the given bit position within that word. Callers must allocate (word, bit) via EngineCore::allocate_cell_bit — the bit is not reusable for the cell’s lifetime.

Source

pub fn publish(&self, value: Value)

Producer-side write: replace the cell’s value, bump the revision, set the intent bit. Three Release stores publish the write across any consumer fiber per cross_fiber_invalidation.md §6. The mutex critical section is held only for the value swap; the atomics run outside it.

Source

pub fn snapshot(&self) -> (Value, u64)

Consumer-side read: snapshot the cell’s value and the revision it was published at. Returns a pair so the caller can update its last_seen[cell] = revision alongside taking the value, without a second cell access.

Trait Implementations§

Source§

impl Debug for SharedCellInner

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more