pub(in crate::depot) use block::QueueBlock;
use std::{cell, mem};
use crate::{
alloc::array,
depot::{
arena::{self, linked::fifo},
queue::{
indexed::{fifo::store, lanes, lanes::runtime},
links, pool, tagged,
},
},
};
mod block;
#[repr(C)]
pub(in crate::depot) struct Fields<K, Q, P> {
pub(in crate::depot) key: cell::UnsafeCell<mem::MaybeUninit<K>>,
pub(in crate::depot) payload: cell::UnsafeCell<mem::MaybeUninit<arena::raw::Value<Q, P>>>,
}
pub(in crate::depot) struct QueueSlot<S> {
pub(in crate::depot) queue: fifo::Fifo,
pub(in crate::depot) state: S,
}
unsafe impl<'a, T, S, const TRACK: bool> crate::depot::raw::Project<usize>
for &'a pool::Lanes<T, S, TRACK>
{
type Output = pool::View<'a, T, S, TRACK>;
unsafe fn project(self, index: usize) -> Self::Output {
pool::View::new(&self.block.store, unsafe {
self.block.slots().get_unchecked(index)
})
}
}
unsafe impl<'a, T, S, const TRACK: bool> crate::depot::raw::Project<usize>
for &'a mut pool::Lanes<T, S, TRACK>
{
type Output = pool::raw::Lane<'a, T, S, TRACK>;
unsafe fn project(self, index: usize) -> Self::Output {
let (store, slots) = self.block.split();
pool::raw::Lane::new(store, unsafe { slots.get_unchecked_mut(index) })
}
}
unsafe impl<'a, T: Copy, P, const N: usize> crate::depot::raw::Project<usize>
for &'a store::Store<T, P, N, ()>
{
type Output = store::Entry<'a, T, P, N, ()>;
unsafe fn project(self, index: usize) -> Self::Output {
unsafe { self.at(index) }
}
}
pub(in crate::depot) unsafe trait LaneStore:
crate::depot::raw::TagStore
{
type Item;
fn nodes(&self) -> &[lanes::Value<Self::Item>];
}
unsafe impl<T, C: crate::depot::raw::Count, const N: usize> crate::depot::raw::TagStore
for array::raw::Block<
lanes::Value<T>,
tagged::Domain<[links::raw::Chain; N], C>,
[links::raw::Chain; N],
>
{
type Head = links::raw::Chain;
type Heads = [links::raw::Chain; N];
fn heads(&self) -> &Self::Heads {
self.state()
}
unsafe fn hook(&self, index: links::Index) -> &tagged::raw::Hook {
&unsafe { self.get_unchecked(index.get()) }.hook
}
}
unsafe impl<T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
crate::depot::raw::TagStore for runtime::Fifo<T, C, L, H>
{
type Head = H;
type Heads = [H];
fn heads(&self) -> &Self::Heads {
self.block.tail()
}
fn is_node(&self, word: u32) -> bool {
(word as usize) < self.block.extent().shape().capacity().count().get()
}
unsafe fn hook(&self, index: links::Index) -> &tagged::raw::Hook {
&unsafe { self.nodes().get_unchecked(index.get()) }.hook
}
}
unsafe impl<T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
crate::depot::raw::LaneStore for runtime::Fifo<T, C, L, H>
{
type Item = T;
fn nodes(&self) -> &[lanes::Value<T>] {
self.block.as_ref()
}
}
unsafe impl<'a, T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
crate::depot::raw::Project<links::Index, links::raw::Chain> for &'a runtime::Fifo<T, C, L, H>
{
type Output = &'a T;
unsafe fn project(self, index: links::Index) -> Self::Output {
unsafe { (*self.nodes().get_unchecked(index.get()).value.get()).assume_init_ref() }
}
}