Struct UnboundedQueue

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

An unbounded lock-free queue. This is the LCSQ from the ACM paper, “A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue” by Ruslan Nikolaev.

Internally, it manages a linked list of bounded queue types and this allows it to grow in an unbounded manner. Since with a reasonable order new queue creation and deletion should be sparse, the operation cost is largely dominated by the internal queues and thus is still extremely fast.

§Example

use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<usize>::new();
queue.enqueue(4);
queue.enqueue(5);

assert_eq!(queue.dequeue(), Some(4));
assert_eq!(queue.dequeue(), Some(5));

Implementations§

Source§

impl<T> UnboundedQueue<T>
where T: Send + Sync,

Source

pub fn new() -> Self

Creates a new UnboundedQueue with a default segment size of 32.

§Examples
use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<()>::new();
assert_eq!(queue.base_segment_capacity(), 32);
Source

pub fn with_segment_size(size: usize) -> Self

Creates a new UnboundedQueue with a particular segment size. The segment size determines the size of each of the internal bounded queues. This method exists to allow developers to customize the internal sizes of the queues.

§Examples
use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<()>::with_segment_size(4);
assert_eq!(queue.base_segment_capacity(), 4);
Source

pub fn base_segment_capacity(&self) -> usize

Returns the base segment size of the unbounded queue.

§Examples
use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<()>::with_segment_size(4);
assert_eq!(queue.base_segment_capacity(), 4);
Source

pub fn enqueue_handle(&self) -> UnboundedEnqueueHandle<'_, T>

Creates an UnboundedEnqueueHandle that allows for the execution of many

§Example
use lfqueue::{UnboundedEnqueueHandle, UnboundedQueue};

let queue = UnboundedQueue::<usize>::new();
let mut handle = queue.enqueue_handle();
handle.enqueue(3);
handle.enqueue(4);
Source

pub fn full_handle(&self) -> UnboundedFullHandle<'_, T>

Source

pub fn enqueue(&self, item: T)

Enqueues a single entry. Internally, this just creates an UnboundedEnqueueHandle and performs a single enqueue operation. If you intend to do several enqueues in a row, please see UnboundedQueue::enqueue_handle.

§Example
use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<usize>::new();
queue.enqueue(4);
Source

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

Dequeues a single entry. Internally, this just creates an UnboundedFullHandle and performs a single dequeue operation. If you intend to do several dequeues in a row, please see UnboundedQueue::full_handle.

§Example
use lfqueue::UnboundedQueue;

let queue = UnboundedQueue::<usize>::new();
queue.enqueue(2);

assert_eq!(queue.dequeue(), Some(2));

Trait Implementations§

Source§

impl<T> Default for UnboundedQueue<T>
where T: Send + Sync,

Source§

fn default() -> Self

Initializes an unbounded queue with a default segment size.

§Example
use lfqueue::UnboundedQueue;
 
let queue = UnboundedQueue::<usize>::default();
queue.enqueue(0);
assert_eq!(queue.dequeue(), Some(0));
Source§

impl<T: Send + Sync> Send for UnboundedQueue<T>

Source§

impl<T: Send + Sync> Sync for UnboundedQueue<T>

Auto Trait Implementations§

§

impl<T> !Freeze for UnboundedQueue<T>

§

impl<T> !RefUnwindSafe for UnboundedQueue<T>

§

impl<T> Unpin for UnboundedQueue<T>

§

impl<T> !UnwindSafe for UnboundedQueue<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.
Source§

impl<T> Reclaim for T