Skip to main content

Crate ds_ring

Crate ds_ring 

Source
Expand description

Fixed-capacity ring buffers: a stack-allocated sample/latency ring and a lock-free single-producer/single-consumer ring, loom-tested.

ds-kit roadmap Part 3.2: latency/sample history and cross-thread handoff both want bounded queues with zero steady-state allocation. This crate is the canonical leaf (layering L0: zero estate deps — any tier may depend on it; the A0 survey measured four crates duplicating ring mechanics to avoid upward edges).

Hot path contract: no panics, no syscalls, and no allocation after construction — SampleRing never allocates at all, SpscRing allocates its slot buffer exactly once in SpscRing::new. The naive reference lives in oracle and is kept forever for differential testing (ds-kit AGENTS.md).

SpscRing is the estate’s sanctioned unsafe exception: UnsafeCell slots behind per-slot sequence atomics (Vyukov bounded-queue protocol), with every block annotated with the acquire/release invariant it relies on and the whole protocol model-checked under loom (tests/loom_spsc.rs). SampleRing contains no unsafe code.

Modules§

oracle
The forever-oracle for differential testing: naive Vec + shift-on-pop spec forms, not optimized. Never deleted, never optimized. Naive reference implementations: the forever-oracle.

Structs§

Iter
Oldest-first iterator over a SampleRing; exact-size.
SampleRing
Fixed-capacity sample/latency ring, stack-allocated, oldest-first.
SpscReceiver
Consumer handle: the only way to try_pop from a channel ring.
SpscRing
Lock-free single-producer/single-consumer ring, fixed const capacity.
SpscSender
Producer handle: the only way to try_push into a channel ring.

Functions§

channel
Pair a ring with its two ends for handing to separate threads. The ring itself lives in an Arc; the handles are the only way the two threads reach it, which documents the SPSC contract at the type level.