o3 0.61.0

shared-nothing primitives
Documentation
use std::{marker, mem};

use crate::{
    alloc::{self, array},
    base::marker::ThreadBound,
    depot::{arena::slab::key, capacity, queue::links},
};

pub(in crate::depot::queue::round) struct Order<Tag> {
    storage: array::Block<links::Hook, capacity::Count, links::Cycle>,
    confined: marker::PhantomData<(ThreadBound, key::Handle<Tag>)>,
}

impl<Tag> Order<Tag> {
    pub(super) fn try_new(count: capacity::Count) -> Result<Self, alloc::Error> {
        let storage = array::Block::try_new(count, links::Cycle::new())?.init(|raw| {
            // SAFETY: Count excludes the sentinel from its slot range.
            let index = unsafe { links::Index::new_usize(raw) };
            links::Hook::new(index)
        });
        Ok(Self {
            storage,
            confined: marker::PhantomData,
        })
    }

    pub(super) const fn ring(&self) -> &links::Cycle {
        self.storage.state()
    }
}

// SAFETY: the joint owner retains every initialized hook for its full lifetime.
unsafe impl<Tag> crate::depot::raw::Hooks for Order<Tag> {
    unsafe fn hook_raw(&self, index: links::Index) -> &links::Hook {
        // SAFETY: the ring/capability retains this exact initialized resident.
        unsafe { self.storage.get_unchecked(index.get()) }
    }
}

const _: () = {
    let _: [(); mem::size_of::<links::Hook>()] = [(); 2 * mem::size_of::<u32>()];
    let _: [(); mem::size_of::<Order<()>>()] = [(); 2 * mem::size_of::<usize>()];
};