Skip to main content

Module shared_cell

Module shared_cell 

Source
Expand description

SharedCell<T> - cross-process single-value cell using the SeqLock protocol over a memory-mapped file.

T: Copy plus a stable #[repr(C)] layout is the contract; readers in different processes will memcpy the same bytes and interpret them identically. The SeqLock retry loop guarantees that a reader never observes a torn write across the writer’s payload-update window.

§SeqLock protocol

Layout (one cache line):

+---------+---------+---------+--------------------------+
| magic   | size    | version | payload [u8; PAYLOAD]    |
+---------+---------+---------+--------------------------+
  u32       u32       u32       up to 52 bytes

Writer protocol:

  1. Bump version from V (even) to V+1 (odd). All concurrent readers now see an odd version and will retry.
  2. Memcpy the new payload bytes into place.
  3. Bump version from V+1 to V+2 (even). Readers resume.

Reader protocol:

  1. Load version (Acquire). If odd, spin and retry.
  2. Memcpy the payload into a local buffer.
  3. Load version again (Acquire). If it changed, retry.
  4. Return the buffered payload.

Structs§

CellHeader
SharedCell

Enums§

SharedCellError

Constants§

CELL_FILE_SIZE
CELL_MAGIC
PAYLOAD_BYTES