Struct Queue

Source
pub struct Queue<T> { /* private fields */ }
Expand description

Atomic queue cloned from https://github.com/max0x7ba/atomic_queue

Should be:

  • Lock-free

Any type can be pushed into the queue, but it’s recommended to use some sort of smart pointer that can be free-ed outside of the critical path.

Uses unsafe internally.

Implementations§

Source§

impl<T> Queue<T>

Source

pub fn new(capacity: usize) -> Self

Create a queue with a certain capacity. Writes will fail when the queue is full.

Source

pub fn push(&self, element: T) -> bool

Push an element into the queue and return true on success.

false will be returned if the queue is full. If there’s contention this operation will wait until it’s able to claim a slot in the queue.

This is a CAS loop to increment the head of the queue, then another to push this element in.

Source

pub fn pop(&self) -> Option<T>

Pop an element from the queue and return true on success.

false will be returned if the queue is empty. If there’s contention this operation will wait until it’s able to claim a slot in the queue.

This is a CAS loop to increment the tail of the queue then another CAS loop to pop the element at this index out.

Source

pub unsafe fn force_pop(&self) -> T

Pop an element from the queue without checking if it’s empty.

§Safety

There’s nothing safe about this.

Source

pub unsafe fn force_push(&self, element: T)

Push an element into the queue without checking if it’s full.

§Safety

There’s nothing safe about this.

Source

pub fn is_empty(&self) -> bool

True if the queue is empty.

Source

pub fn len(&self) -> usize

Get the length of the queue.

Trait Implementations§

Source§

impl<T> Drop for Queue<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send> Send for Queue<T>

Source§

impl<T: Send> Sync for Queue<T>

Auto Trait Implementations§

§

impl<T> !Freeze for Queue<T>

§

impl<T> !RefUnwindSafe for Queue<T>

§

impl<T> Unpin for Queue<T>
where T: Unpin,

§

impl<T> UnwindSafe for Queue<T>
where T: UnwindSafe,

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.