Module queue

Module queue 

Source
Expand description

A bounded SPSC ring buffer stored in leased fabric memory.

FabricQueue<T> implements a single-producer single-consumer FIFO queue backed by a leased memory region. Elements are serialized with postcard into fixed-size slots arranged in a circular buffer.

§Memory layout

Offset 0:  [header]  head: u64 (8) | tail: u64 (8) | capacity: u64 (8) | stride: u64 (8)
Offset 32: [slots]   slot 0 (stride bytes) | slot 1 | ... | slot (capacity-1)

head is the next index to read from, tail is the next index to write to. The queue is empty when head == tail and full when (tail + 1) % capacity == head. One slot is always reserved for the empty/full distinction, so the usable capacity is capacity - 1.

§Example

use grafos_collections::queue::FabricQueue;
use grafos_std::mem::MemBuilder;

let lease = MemBuilder::new().min_bytes(4096).acquire()?;
let mut q: FabricQueue<u32> = FabricQueue::new(lease, 16, 16)?;

q.push(&1)?;
q.push(&2)?;
assert_eq!(q.pop()?, Some(1)); // FIFO order

Structs§

FabricQueue
A bounded SPSC ring buffer stored in leased fabric memory.