pub struct MPSCQueue<T> { /* private fields */ }Expand description
A low-latency implementation of MPSC (multi-producer single-consumer) queue
§Example
use frozen_core::mpscq::MPSCQueue;
let queue = MPSCQueue::<usize>::default();
queue.push(0x100);
queue.push(0x200);
let batch: Vec<usize> = queue.drain();
assert_eq!(batch.len(), 2);
assert_eq!(batch, vec![0x200, 0x100]);Implementations§
Source§impl<T> MPSCQueue<T>
impl<T> MPSCQueue<T>
Sourcepub fn drain(&self) -> Vec<T>
pub fn drain(&self) -> Vec<T>
Drain the current batch of items from the MPSCQueue
§Ordering
The queue internally uses a linked list like structure for storing T, therefore entries
are stored in LIFO order.
§Multiple Consumers
By design MPSCQueue::drain is thread safe, but draining from multiple threads is
semantically incorrect. In the MPSC model, there should only be a single consumer, while
there can be many producers.
§Example
use frozen_core::mpscq::MPSCQueue;
let queue = MPSCQueue::<u8>::default();
queue.push(0x0A);
queue.push(0x0B);
queue.push(0x0C);
let batch = queue.drain();
assert_eq!(batch.len(), 3);
assert_eq!(batch, vec![0x0C, 0x0B, 0x0A]);Trait Implementations§
impl<T> Send for MPSCQueue<T>
impl<T> Sync for MPSCQueue<T>
Auto Trait Implementations§
impl<T> !Freeze for MPSCQueue<T>
impl<T> RefUnwindSafe for MPSCQueue<T>
impl<T> Unpin for MPSCQueue<T>
impl<T> UnsafeUnpin for MPSCQueue<T>
impl<T> UnwindSafe for MPSCQueue<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more