Struct mpmcpq::PriorityQueue
source · pub struct PriorityQueue<M, P>where
M: Send,
P: PartialOrd + Ord,{ /* private fields */ }
Expand description
A queue which orders messages by priority
Implementations§
source§impl<M, P> PriorityQueue<M, P>where
M: Send,
P: PartialOrd + Ord,
impl<M, P> PriorityQueue<M, P>where
M: Send,
P: PartialOrd + Ord,
sourcepub fn sync(&self, stash: &mut Stash<'_, M, P>)
pub fn sync(&self, stash: &mut Stash<'_, M, P>)
Inserts all elements from the stash to the PriorityQueue, empties stash. This function waits until the on the queue is locked.
sourcepub fn send(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
pub fn send(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
Pushes an message with prio onto the queue, uses a Stash as temporary storage when the queue is contended. Drains the stash in the uncontended case. This function does not wait for the lock on the queue.
sourcepub fn send_sync(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
pub fn send_sync(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
Pushes a message with prio onto the queue, drains the Stash first. This function waits until the on the queue is locked.
sourcepub fn send_stashed(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
pub fn send_stashed(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)
Pushes an message to the Stash. will not try to send data to the queue. Use this to combine some messages together before calling sync() to send them. This function does not wait for the lock on the queue.
sourcepub fn send_batched(
&self,
message: M,
prio: P,
batch_size: usize,
stash: &mut Stash<'_, M, P>
)
pub fn send_batched(
&self,
message: M,
prio: P,
batch_size: usize,
stash: &mut Stash<'_, M, P>
)
Combines the above to collect at least ‘batch_size’ messages in the stash before trying to send them out. Use this to batch some messages together before calling sync() to send them. This function does not wait for the lock on the queue.
sourcepub fn send_nostash(&self, message: M, prio: P)
pub fn send_nostash(&self, message: M, prio: P)
Pushes a message with prio onto the queue without using a stash. This function waits until the on the queue is locked. No stash involved, this should be not used with threads that have a stash since it won’t get drained first. Can be used to send synchronous out-of-band message bypassing the stash.
sourcepub fn recv_guard(&self) -> ReceiveGuard<'_, M, P>
pub fn recv_guard(&self) -> ReceiveGuard<'_, M, P>
Returns the smallest message from a queue. This message is wraped in a ReceiveGuard/Message
sourcepub fn try_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>
pub fn try_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>
Try to get the smallest message from a queue. Will return Some
sourcepub fn maybe_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>
pub fn maybe_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>
Try to get the smallest message from a queue. Will return Some
sourcepub fn try_recv(&self) -> Option<Message<M, P>>
pub fn try_recv(&self) -> Option<Message<M, P>>
Try to get the smallest message from a queue. Will return Some
sourcepub fn maybe_recv(&self) -> Option<Message<M, P>>
pub fn maybe_recv(&self) -> Option<Message<M, P>>
Try to get the smallest message from a queue. Will return Some
sourcepub fn in_progress(&self) -> usize
pub fn in_progress(&self) -> usize
Returns the number of messages in flight. This is the .len() plus any receiver that still holds a guard. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when the Stash contains no messages. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.