o3 0.62.0

shared-nothing primitives
Documentation
use std::cell::Cell;

use crate::{buffer::storage, depot::queue::links};

pub(super) mod account;

pub(super) const END: u32 = links::Index::encode(None);

pub(super) const fn link(index: u32, limit: u32) -> u32 {
    if index == limit { END } else { index }
}

#[repr(transparent)]
pub(super) struct Free(Cell<u32>);

impl Free {
    pub(super) const fn new(limit: u32) -> Self {
        Self(Cell::new(link(0, limit)))
    }

    pub(super) fn head(&self) -> Option<Key> {
        Some(Key(links::Index::decode(self.0.get())?.raw()))
    }
}

/// One index issued by an exact pool slot list.
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(in crate::buffer::pool) struct Key(u32);

impl Key {
    pub(super) const FIRST: Self = Self(0);

    /// # Safety
    /// The index belongs to this exact initialized pool's slot list.
    pub(super) const unsafe fn new(index: u32) -> Self {
        Self(index)
    }

    pub(super) const fn get(self) -> u32 {
        self.0
    }

    /// # Safety
    /// The caller owns this retired entry in the head's exact table.
    pub(super) unsafe fn recycle(self, head: &Free, prefix: &storage::raw::Prefix) {
        unsafe { prefix.write(head.0.get()) };
        head.0.set(self.0);
    }

    /// # Safety
    /// The prefix belongs to the exclusively claimed head; its live word will name this slot.
    pub(super) unsafe fn occupy(self, head: &Free, prefix: &storage::raw::Prefix) {
        head.0.set(prefix.word());
        unsafe { prefix.write(self.0) };
    }
}

const _: () = {
    assert!(size_of::<Key>() == size_of::<u32>());
    assert!(size_of::<Free>() == size_of::<u32>());
};