#![warn(missing_docs, missing_debug_implementations, unreachable_pub)]
#![no_std]
extern crate alloc;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::fmt;
use core::mem::MaybeUninit;
use config::{UnsignedLong, UnsignedShort};
use crate::loom_exports::cell::UnsafeCell;
mod config;
pub mod fifo;
pub mod lifo;
mod loom_exports;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StealError {
Empty,
Busy,
}
impl fmt::Display for StealError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StealError::Empty => write!(f, "cannot steal from empty queue"),
StealError::Busy => write!(f, "a concurrent steal operation is ongoing"),
}
}
}
#[inline]
fn pack(value1: UnsignedShort, value2: UnsignedShort) -> UnsignedLong {
((value1 as UnsignedLong) << UnsignedShort::BITS) | value2 as UnsignedLong
}
#[inline]
fn unpack(value: UnsignedLong) -> (UnsignedShort, UnsignedShort) {
(
(value >> UnsignedShort::BITS) as UnsignedShort,
value as UnsignedShort,
)
}
fn allocate_buffer<T>(len: usize) -> Box<[UnsafeCell<MaybeUninit<T>>]> {
let mut buffer = Vec::with_capacity(len);
buffer.resize_with(len, || UnsafeCell::new(MaybeUninit::uninit()));
buffer.into_boxed_slice()
}