use std::mem;
pub use bounds::Bounds;
use crate::depot::{index::Initialized, queue::indexed::fifo};
mod bounds;
#[must_use]
pub struct Entry<'a, T: Copy + Eq, I: crate::depot::raw::Compact = u32> {
pub(in crate::depot::queue) owner: &'a mut fifo::List<T, I>,
pub(in crate::depot::queue) index: I,
}
impl<'a, T: Copy + Eq, I: crate::depot::raw::Compact> Entry<'a, T, I> {
pub fn index(&self) -> I {
self.index
}
pub fn from_source<C>(source: Admission<'a, T, I, C>) -> (Self, C) {
let ((owner, context), index) = source.into_inner();
(Self { owner, index }, context)
}
pub fn schedule<const KEEP_EQUAL: bool>(&mut self, value: T) {
let entry = unsafe { self.owner.store.at(self.index.into_raw() as usize) };
if entry.is_linked::<0>() {
if KEEP_EQUAL && unsafe { (*entry.value::<0>()).assume_init_read() } == value {
return;
}
unsafe { entry.write_back::<0, true>(value) };
} else {
unsafe { entry.write_back::<0, false>(value) };
}
}
pub fn unlink(&mut self, expected: T) {
let entry = unsafe { self.owner.store.at(self.index.into_raw() as usize) };
if entry.is_linked::<0>() && unsafe { (*entry.value::<0>()).assume_init_read() } == expected
{
unsafe { entry.unlink::<0, false>() };
}
}
}
const _: [(); 2 * mem::size_of::<usize>()] = [(); mem::size_of::<Entry<'_, u64>>()];
const _: [(); 2 * mem::size_of::<usize>()] = [(); mem::size_of::<Option<Entry<'_, u64>>>()];
type Admission<'a, T, I, C> =
crate::depot::raw::Proof<((&'a mut fifo::List<T, I>, C), I), Initialized<()>>;