Type Alias ConstBoundedQueue

Source
pub type ConstBoundedQueue<T, const N: usize> = BoundedQueue<T, [UnsafeCell<Option<T>>; N], [CachePadded<AtomicUsize>; N], 0>;
Expand description

A constant generic constant bounded queue, this implements the SCQ from the ACM paper, “A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue” by Ruslan Nikolaev.

Generally, if you want to work with these what you really want is the const_queue! macro which will configure the size for you properly. Due to the inner workings of the data structure, it needs 2 * N slots to operate properly. Thus, to make a constant queue of size 2, the constant parameter should be set to 4. To ease the burden of this, the const_queue! macro exists.

§Preferred Initialization

 

§Manual Example

use lfqueue::{ConstBoundedQueue, ScqError};

// Make a queue of size 4.
let queue = ConstBoundedQueue::<usize, 4>::new_const();

assert_eq!(queue.capacity(), 2);
assert!(queue.enqueue(2).is_ok());
assert!(queue.enqueue(3).is_ok());
assert_eq!(queue.enqueue(4), Err(ScqError::QueueFull));

Aliased Type§

pub struct ConstBoundedQueue<T, const N: usize> { /* private fields */ }

Implementations§

Source§

impl<T, const N: usize> ConstBoundedQueue<T, N>

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));