pub mod checked;
pub mod intrusive;
pub mod simple;
macro_rules! boilerplate {
(
$slots:ty => $store:ident,
for<$read_lt:lifetime> $read:ty => $reader:ident,
for<$exclusive_lt:lifetime> $exclusive:ty => $writer:ident,
) => {
#[derive(Debug)]
pub struct $store {
store: $crate::store::Store<$slots>,
}
impl $store {
pub fn readable_slots(&self) -> usize {
self.store.frozen().end as usize
}
pub fn writable_slots(&self) -> usize {
self.store.frozen().start as usize
}
pub fn reclaim(&self) -> Option<usize> {
self.store.try_drain()
}
pub fn acquire(&self) -> Option<$writer<'_>> {
self.store.acquire().map(Writer::new)
}
#[must_use = "result indicates success or failure"]
pub fn retire(&self, i: usize) -> bool {
self.store.retire(i).is_ok()
}
pub fn reader(&self) -> Option<$reader<'_>> {
match self.store.guard(|slots, guard| slots.reader(guard)) {
Ok(reader) => Some($reader::new(reader)),
Err($crate::epoch::Unavailable) => None,
}
}
}
#[derive(Debug)]
pub struct $reader<$read_lt> {
reader: $read,
}
impl<$read_lt> $reader<$read_lt> {
fn new(reader: $read) -> Self {
Self { reader }
}
}
#[derive(Debug)]
pub struct $writer<$exclusive_lt> {
slot: $crate::store::Exclusive<$exclusive_lt, $exclusive>,
}
impl<$exclusive_lt> $writer<$exclusive_lt> {
fn new(slot: $crate::store::Exclusive<$exclusive_lt, $exclusive>) -> Self {
Self { slot }
}
pub fn publish(self) {
self.slot.publish();
}
}
};
}
use boilerplate;