o3 0.62.0

shared-nothing primitives
Documentation
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,
}

// SAFETY: Live retains this exact allocated, initialized lane and the owner's borrow.
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)
        })
    }
}

// SAFETY: Live retains the exclusive original owner and this initialized lane.
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) })
    }
}

// SAFETY: the initialized-node proof retains this exact allocation and its original borrow.
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 {
        // SAFETY: Project admits an initialized physical node in this exact owner.
        unsafe { self.at(index) }
    }
}

/// Co-located initialized hooks and phase-controlled affine payloads.
/// # Safety
/// Hooks match nodes; linked hooks own initialized payloads, and entries exclude mutation.
pub(in crate::depot) unsafe trait LaneStore:
    crate::depot::raw::TagStore
{
    type Item;
    fn nodes(&self) -> &[lanes::Value<Self::Item>];
}

// SAFETY: the retained Domain fixes disjoint node/endpoint ranges and the inline heads.
// These projections expose only metadata; callers of raw mutation retain membership authority.
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 {
        // SAFETY: this input names an initialized hook in the same fixed backing.
        &unsafe { self.get_unchecked(index.get()) }.hook
    }
}

// SAFETY: construction retains the allocation's validated immutable shape and initializes every 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
    }
}

// SAFETY: this owner initializes every hook and publishes values before membership.
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()
    }
}

// SAFETY: the initialized lane proof retains this exact owner's live payload.
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() }
    }
}