Skip to main content

Crate subms_spsc_ring_buffer

Crate subms_spsc_ring_buffer 

Source
Expand description

Wait-free SPSC ring buffer. Single producer, single consumer, bounded.

Sized to a power of two; index modulo is a bitmask, not a %. Head and tail counters live on their own cache lines (128-byte padding) to keep the producer’s writes from invalidating the consumer’s read line. Each side caches the opposite index and only re-reads through the atomic when its own cache says full / empty.

use subms_spsc_ring_buffer::SpscRingBuffer;

let (mut tx, mut rx) = SpscRingBuffer::with_capacity(64);
tx.try_push(42u32).unwrap();
assert_eq!(rx.try_pop(), Some(42));
assert_eq!(rx.try_pop(), None);

Full writeup, design notes and measured benchmarks: https://www.submillisecond.com/cookbook/recipes/subms-spsc-ring-buffer

Re-exports§

pub use features::metrics::InstrumentedSpsc;
pub use features::metrics::RingMetrics;
pub use features::metrics::RingMetricsSnapshot;
pub use features::mpmc_disruptor::DisruptorConsumer;
pub use features::mpmc_disruptor::DisruptorProducer;
pub use features::mpmc_disruptor::MpmcDisruptor;
pub use features::mpsc_fan_in::MpscFanIn;
pub use features::mpsc_fan_in::MpscFanInConsumer;
pub use features::mpsc_fan_in::MpscFanInProducer;
pub use features::wait_strategies::BlockingSpscConsumer;
pub use features::wait_strategies::BlockingSpscProducer;
pub use features::wait_strategies::BusySpin;
pub use features::wait_strategies::ParkStrategy;
pub use features::wait_strategies::WaitStrategy;
pub use features::wait_strategies::YieldStrategy;

Modules§

features
Opt-in feature catalog. Each submodule is gated by its own Cargo feature flag and adds a specific capability without bloating the core build.
recipe
SubMsRecipe impl. Behind the harness feature.

Structs§

Consumer
Consumer handle. Move it to the consuming thread.
Producer
Producer handle. Move it to the producing thread; the type system enforces the SPSC invariant.
SpscRingBuffer
Constructor namespace. Use SpscRingBuffer::with_capacity.