Expand description
A wait-free single-producer single-consumer (SPSC) queue to send data to another thread. It is based on the improved FastForward queue.
This is similar to std::sync::mpsc, but restricted to a single producer and a single
consumer and backed by a fixed-size ring buffer instead of an unbounded linked list. Because
of this, Sender::try_send and Receiver::try_recv never block and never allocate: they
return immediately instead of parking the calling thread the way std’s blocking send/recv
do.
§Example
use waitfree_sync::spsc;
// Type ──╮ ╭─ Capacity
let (mut tx, mut rx) = spsc::spsc::<u64>(8);
tx.try_send(234);
assert_eq!(rx.try_recv(),Ok(234u64));§Behavior for full and empty queue.
If the queue is full, Sender::try_send returns SendError::NoSpaceLeft.
If the queue is empty, Receiver::try_recv returns TryRecvError::Empty.
Structs§
Enums§
- Send
Error - An error returned from the
Sender::try_sendfunction on aSender. - TryRecv
Error - This enumeration is the list of the possible reasons that
Receiver::try_recvcould not return data when called.
Functions§
- spsc
- Create a new wait-free SPSC queue. The
capacitymust be a power of two, which is validate during runtime.