pub struct Sender<T, const P: usize, const NUM_SEGS_P2: usize> { /* private fields */ }Expand description
Blocking MPMC Queue - Multi-Producer Single-Consumer with blocking operations
§Type Parameters
T: The type of elements stored in the queue (must be Copy)P: log2 of segment size (default 8 = 256 items/segment)NUM_SEGS_P2: log2 of number of segments (default 2 = 4 segments, total capacity ~1024)
§Examples
ⓘ
use bop_mpmc::mpsc_blocking::MpscBlocking;
use std::thread;
use std::time::Duration;
let mpsc = MpscBlocking::<i32>::new();
// Producer thread
let mpsc_producer = mpsc.clone();
thread::spawn(move || {
thread::sleep(Duration::from_millis(100));
mpsc_producer.push(42).unwrap();
});
// Consumer blocks until item is available
let value = mpsc.pop_blocking().unwrap();
assert_eq!(value, 42);
```ignoreImplementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Sender<T, P, NUM_SEGS_P2>
Sourcepub fn producer_count(&self) -> usize
pub fn producer_count(&self) -> usize
Get the number of registered producers
Sourcepub fn producer_id(&self) -> usize
pub fn producer_id(&self) -> usize
Get the producer ID for this handle
Sourcepub fn try_push(&mut self, value: T) -> Result<(), PushError<T>>
pub fn try_push(&mut self, value: T) -> Result<(), PushError<T>>
Push a value onto the queue
This will use the thread-local SPSC queue for this producer. If successful, notifies any waiting consumer.
Sourcepub fn push_spin(&mut self, value: T) -> Result<(), PushError<T>>
pub fn push_spin(&mut self, value: T) -> Result<(), PushError<T>>
Push a value onto the queue (spins if full)
This will use the thread-local SPSC queue for this producer. If successful, notifies any waiting consumer.
Sourcepub fn try_push_n(&mut self, values: &[T]) -> Result<usize, PushError<()>>
pub fn try_push_n(&mut self, values: &[T]) -> Result<usize, PushError<()>>
Push multiple values in bulk
Sourcepub unsafe fn unsafe_try_push(&self, value: T) -> Result<(), PushError<T>>
pub unsafe fn unsafe_try_push(&self, value: T) -> Result<(), PushError<T>>
Push a value onto the queue
This will use the thread-local SPSC queue for this producer. If successful, notifies any waiting consumer.
Trait Implementations§
Auto Trait Implementations§
impl<T, const P: usize, const NUM_SEGS_P2: usize> Freeze for Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !RefUnwindSafe for Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Send for Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Sync for Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Unpin for Sender<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !UnwindSafe for Sender<T, P, NUM_SEGS_P2>
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