pub fn new<T, const CAPACITY: usize, A>(
options: Options<A>,
) -> (Producer<T, CAPACITY, A>, Consumer<T, CAPACITY, A>)where
A: Allocator,Expand description
Creates a new SPSC queue with CAPACITY slots using the specified allocator.
CAPACITY must be a power of two (compile-time enforced). The slot
buffer is allocated up front and locked into RAM via mlock so the
hot path never page-faults.
§Examples
use low_latency_data_structures::spsc::{self, new};
use low_latency_data_structures::mem::global::GlobalAllocator;
let (mut producer, mut consumer) = new::<u64, 8, GlobalAllocator>(
spsc::Options::global_mlocked(),
);
assert_eq!(producer.push(1), None);
assert_eq!(consumer.pop(), Some(1));Capacities that are not powers of two fail to compile:
ⓘ
use low_latency_data_structures::spsc::{self, new};
use low_latency_data_structures::mem::global::GlobalAllocator;
seq!(N in 2..20 {
{
const CAP: usize = 2usize.wrapping_pow(N);
let _fail = new::<u64, { CAP - 1 }, GlobalAllocator>(
spsc::Options::global_mlocked(),
);
let _fail = new::<u64, { CAP + 1 }, GlobalAllocator>(
spsc::Options::global_mlocked(),
);
}
});