dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use std::cell;

use o3::{
    alloc,
    base::{marker::ThreadBound, num},
};
use resident::retire::Release;
pub(crate) use sealed::outbound::Outbound;
use slots::Index;
pub(crate) use slots::{Close, Closures, Create, Creation, Solo};

use crate::{
    driver::{
        route,
        route::{indices, indices::SlotIndex, table},
        settings,
    },
    io::fd::{handles, identity},
};

mod sealed;
mod slots;
use sealed::Table;

mod resident;
pub(crate) mod retire;

pub(crate) struct Domain {
    pub(in crate::io::fd) resident: resident::Store,
    accept: table::Capacity,
    closed: cell::Cell<retire::Completed>,
    outbound: Table,
}

impl TryFrom<settings::FileSlots> for Domain {
    type Error = alloc::Error;

    fn try_from(layout: settings::FileSlots) -> Result<Self, Self::Error> {
        Ok(Self {
            resident: resident::Store::try_new(layout.capacity())?,
            accept: layout.accept(),
            closed: cell::Cell::new(retire::Completed::EMPTY),
            outbound: Table::try_new(layout)?,
        })
    }
}

impl Domain {
    pub(crate) const fn retire(&self) -> retire::View<'_> {
        retire::View {
            domain: self,
            thread: ThreadBound::NEW,
        }
    }

    pub(crate) fn claim<'d>(
        &'d self,
        slot: handles::PhysicalSlot,
    ) -> Option<identity::Identity<'d>> {
        let version = self.resident.try_claim(SlotIndex::from(slot))?;
        Some(identity::Identity::new(slot, version))
    }

    pub(crate) fn release(&self, id: identity::Identity<'_>) {
        Release::new(&self.resident, id).cancel();
    }

    pub(crate) fn set_target(&self, id: identity::Identity<'_>, target: route::Token) {
        self.resident
            .set_target(id.index(), id.generation(), target);
    }

    pub(crate) fn target(&self, id: identity::Identity<'_>) -> Option<route::Token> {
        self.resident.target(id.index(), id.generation())
    }

    pub(crate) fn target_at(&self, index: indices::SlotIndex) -> Option<route::Token> {
        self.resident.target_at(index)
    }

    pub(crate) fn target_for(
        &self,
        index: indices::SlotIndex,
        version: num::Generation,
    ) -> Option<route::Token> {
        self.resident.target(index, version)
    }

    pub(crate) const fn outbound_cap(&self) -> table::Capacity {
        self.outbound.capacity()
    }

    pub(crate) const fn accept_cap(&self) -> table::Capacity {
        self.accept
    }
}