Skip to main content

Crate yring

Crate yring 

Source
Expand description

Bounded SPSC ring with ypipe-style batched flush/prefetch.

Three pointers:

  • head: consumer read position (AtomicUsize, consumer-owned)
  • tail: writer position (plain usize, producer-only, no atomic)
  • flush: last flushed position (AtomicUsize, producer writes, consumer reads)

push writes to the ring with zero atomics. flush makes all pending writes visible with one Release store. pop reads with zero atomics. prefetch loads all flushed items with one Acquire load. Result: 1 atomic per batch on each side.

Structs§

AsyncConsumer
Async receiving half. Implements Stream.
AsyncProducer
Async sending half. Wakes the consumer on flush when the ring was empty.
Consumer
Receiving half. Send but not Sync.
Producer
Sending half. Send but not Sync.

Enums§

FlushResult
Result of a flush operation.

Functions§

async_spsc
Create an async bounded SPSC ring with the given capacity (rounded up to next power of two).
spsc
Create a bounded SPSC ring with the given capacity (rounded up to next power of two).