Struct BoundedQueue

Source
pub struct BoundedQueue<T, I, RING, const SEAL: usize>
where I: Sealed,
{ /* private fields */ }
Expand description

The bounded queue type from the ACM paper. This uses two SCQ rings internally, one that keeps track of free indices and the other that keeps track of the allocated indices.

Implementations§

Source§

impl<T, const N: usize> BoundedQueue<T, [UnsafeCell<Option<T>>; N], [CachePadded<AtomicUsize>; N], 0>

Source

pub fn new_const() -> Self

A helper function for creating constant bounded queues, will automatically try to calculate the correct order.

§Panics

This function will panic if the value is not a power of two and also if the value is zero as we cannot initialize zero sized constant bounded queues.

§Example
use lfqueue::{ConstBoundedQueue, ScqError};

let queue = ConstBoundedQueue::<usize, 4>::new_const();
assert!(queue.enqueue(2).is_ok());
assert!(queue.enqueue(3).is_ok());
assert_eq!(queue.enqueue(4), Err(ScqError::QueueFull));
Source§

impl<T, I, P, const S: usize> BoundedQueue<T, I, P, S>
where I: AsRef<[UnsafeCell<Option<T>>]> + Sealed, P: AsRef<[CachePadded<AtomicUsize>]> + Sealed,

Source

pub const MAX_ORDER: usize = 63usize

Source

pub const MIN_ORDER: usize = 0usize

Source

pub fn capacity(&self) -> usize

Returns the capacity of the bounded ring. This is 2 ^ order.

§Example
use lfqueue::ConstBoundedQueue;
 
let value = ConstBoundedQueue::<usize, 4>::new_const();
assert_eq!(value.capacity(), 2);
Source

pub fn enqueue(&self, item: T) -> Result<(), ScqError>

Enqueues an element to the bounded queue.

§Example
use lfqueue::AllocBoundedQueue;

let queue = AllocBoundedQueue::<usize>::new(2);
assert_eq!(queue.enqueue(4), Ok(()));
assert_eq!(queue.dequeue(), Some(4));
Source

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

Dequeues an element from the bounded queue.

§Example
use lfqueue::AllocBoundedQueue;

let queue = AllocBoundedQueue::<usize>::new(2);
assert_eq!(queue.enqueue(4), Ok(()));
assert_eq!(queue.dequeue(), Some(4));
Source§

impl<T, const MODE: usize> BoundedQueue<T, Box<[UnsafeCell<Option<T>>]>, Box<[CachePadded<AtomicUsize>]>, MODE>

Source

pub fn new(size: usize) -> Self

Allocates a bounded queue, this method backs most of he

Trait Implementations§

Source§

impl<T: Debug, I, RING: Debug, const SEAL: usize> Debug for BoundedQueue<T, I, RING, SEAL>
where I: Sealed + Debug,

Source§

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

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

impl<T: Send + Sync, I: Sealed, R, const SEAL: usize> Send for BoundedQueue<T, I, R, SEAL>

Source§

impl<T: Send + Sync, I: Sealed, R, const SEAL: usize> Sync for BoundedQueue<T, I, R, SEAL>

Auto Trait Implementations§

§

impl<T, I, RING, const SEAL: usize> !Freeze for BoundedQueue<T, I, RING, SEAL>

§

impl<T, I, RING, const SEAL: usize> RefUnwindSafe for BoundedQueue<T, I, RING, SEAL>

§

impl<T, I, RING, const SEAL: usize> Unpin for BoundedQueue<T, I, RING, SEAL>
where I: Unpin, RING: Unpin, T: Unpin,

§

impl<T, I, RING, const SEAL: usize> UnwindSafe for BoundedQueue<T, I, RING, SEAL>
where I: UnwindSafe, RING: UnwindSafe, 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.
Source§

impl<T> Reclaim for T