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§

Create a new PriorityQueue

Examples found in repository?
src/mpmcpq.rs (line 27)
26
27
28
    fn default() -> Self {
        Self::new()
    }

Inserts all elements from the stash to the PriorityQueue, empties stash. This function waits until the on the queue is locked.

Examples found in repository?
src/stash.rs (line 62)
60
61
62
63
64
    fn drop(&mut self) {
        if let Some(pq) = self.pq {
            pq.sync(self);
        }
    }

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.

Examples found in repository?
src/mpmcpq.rs (line 144)
138
139
140
141
142
143
144
145
146
    pub fn send_batched(&self, message: M, prio: P, batch_size: usize, stash: &mut Stash<M, P>) {
        if stash.len() <= batch_size {
            // append to the stash
            self.send_stashed(message, prio, stash);
        } else {
            // try to send
            self.send(message, prio, stash);
        }
    }

Pushes a message with prio onto the queue, drains the Stash first. This function waits until the on the queue is locked.

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.

Examples found in repository?
src/mpmcpq.rs (line 141)
138
139
140
141
142
143
144
145
146
    pub fn send_batched(&self, message: M, prio: P, batch_size: usize, stash: &mut Stash<M, P>) {
        if stash.len() <= batch_size {
            // append to the stash
            self.send_stashed(message, prio, stash);
        } else {
            // try to send
            self.send(message, prio, stash);
        }
    }

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.

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.

Returns the smallest message from a queue. This message is wraped in a ReceiveGuard/Message

Try to get the smallest message from a queue. Will return Some when a message is available. This will not wait on the queue lock.

Try to get the smallest message from a queue. Will return Some when a message is available. This will wait on the queue lock but return None when the queue is empty.

Returns the smallest message from a queue.

Try to get the smallest message from a queue. Will return Some when a message is available. This will not wait on the queue lock.

Try to get the smallest message from a queue. Will return Some when a message is available. This will wait on the queue lock but return None when the queue is empty.

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.

Returns true when the Stash contains no messages. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.

Returns the number of messages in the stash. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.

Reserves capacity for at least additional more elements to be inserted in the PriorityQueue.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.