cordyceps::mpsc_queue

Struct OwnedConsumer

Source
pub struct OwnedConsumer<T: Linked<Links<T>>> { /* private fields */ }
Expand description

An owned handle that holds the right to dequeue elements from the queue.

This can be used when one thread wishes to dequeue many elements at a time, to avoid the overhead of ensuring mutual exclusion on every dequeue or try_dequeue call.

This type is returned by the MpscQueue::consume_owned and MpscQueue::try_consume_owned methods.

This is similar to the Consumer type, but the queue is stored in an Arc rather than borrowed. This allows a single OwnedConsumer instance to be stored in a struct and used indefinitely.

Since the queue is stored in an Arc, this requires the alloc feature flag to be enabled.

Implementations§

Source§

impl<T: Linked<Links<T>>> OwnedConsumer<T>

Source

pub fn dequeue(&self) -> Option<T::Handle>

Dequeue an element from the queue.

As discussed in the algorithm description on 1024cores.net, it is possible for this queue design to enter an inconsistent state if the consumer tries to dequeue an element while a producer is in the middle of enqueueing a new element. If this occurs, the consumer must briefly wait before dequeueing an element. This method will wait by spinning with an exponential backoff if the queue is in an inconsistent state.

The Consumer::try_dequeue will return an error rather than waiting when the queue is in an inconsistent state.

§Returns
  • Some(T::Handle) if an element was successfully dequeued
  • None if the queue is empty
Source

pub fn try_dequeue(&self) -> Result<T::Handle, TryDequeueError>

Try to dequeue an element from the queue, without waiting if the queue is in an inconsistent state.

As discussed in the algorithm description on 1024cores.net, it is possible for this queue design to enter an inconsistent state if the consumer tries to dequeue an element while a producer is in the middle of enqueueing a new element. If this occurs, the consumer must briefly wait before dequeueing an element. This method returns TryDequeueError::Inconsistent when the queue is in an inconsistent state.

The Consumer::dequeue method will instead wait (by spinning with an exponential backoff) when the queue is in an inconsistent state.

§Returns
§Returns
  • Some(T::Handle) if an element was successfully dequeued
  • None if the queue is empty
Source

pub fn has_producers(&self) -> bool

Returns true if any producers exist for this queue.

Trait Implementations§

Source§

impl<T: Linked<Links<T>>> Debug for OwnedConsumer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Linked<Links<T>>> Drop for OwnedConsumer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for OwnedConsumer<T>

§

impl<T> !RefUnwindSafe for OwnedConsumer<T>

§

impl<T> Send for OwnedConsumer<T>
where T: Send, <T as Linked<Links<T>>>::Handle: Send,

§

impl<T> Sync for OwnedConsumer<T>
where T: Send, <T as Linked<Links<T>>>::Handle: Send,

§

impl<T> Unpin for OwnedConsumer<T>

§

impl<T> !UnwindSafe for OwnedConsumer<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.