dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
//! Raw application boundary. [`App`] owns complete lifecycle traversal;
//! runtime-owned session roots choose when it may run.
use std::{num::NonZero, ops::ControlFlow, pin};

use crate::driver::{self, schedule};
use o3::base::{cell::region, num::bounded::U32};

use crate::executor;

mod app;
mod owner;
mod plan;
mod progress;

pub use crate::io::event::{Dispatch, Occupied};
pub use app::{App, Layout};
pub(crate) use owner::{Backing, Draining, Live, Owner, View};
pub use plan::{Census, Flat, Plan, Sweep};
pub use progress::Progress;

/// Cooperative drain while the complete application remains installed.
///
/// # Safety
/// Preserve every admitted owner's identity, presence, address, and routes through
/// finish. `begin` and `force` must not replace owners or reclaim retained storage.
/// Cooperative quiescence does not authorize reclamation: the runtime still
/// shuts down every admitted owner and drains native operations before finish.
pub unsafe trait Drain<'d>: executor::raw::App<'d> {
    fn begin(
        self: pin::Pin<&mut Self>,
        turn: schedule::Turn<'_, 'd>,
        driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
    );

    /// Reports drain work after the application's pre-park traversal.
    /// `Runnable` requires another turn for work that can proceed now;
    /// `Waiting` retains the external wake or deadline needed to proceed.
    /// `Quiescent` reports completed cooperative drain, not reclaimed owners.
    /// The runtime combines this signal with application progress before waiting.
    fn progress(
        self: pin::Pin<&Self>,
        region: &region::Token<region::Identity<'d>>,
        state: Option<&mut schedule::Waits<'d>>,
    ) -> ControlFlow<()>;

    fn force(
        self: pin::Pin<&mut Self>,
        turn: schedule::Turn<'_, 'd>,
        driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
    );
}

/// One complete coordinator count classified at installation.
#[derive(Clone, Copy, Debug)]
pub enum Count {
    Bounded(U32<0, { schedule::LIMIT as u32 }>),
    Excess(NonZero<usize>),
}

impl Count {
    pub const fn new(value: usize) -> Self {
        match U32::from_usize(value) {
            Some(value) => Self::Bounded(value),
            None => Self::Excess(NonZero::<usize>::MIN.saturating_add(value - 1)),
        }
    }

    pub const fn get(self) -> usize {
        match self {
            Self::Bounded(value) => value.into_usize(),
            Self::Excess(value) => value.get(),
        }
    }

    pub(in crate::executor::raw) fn admit<E>(self) -> Result<(), executor::InstallError<E>> {
        match self {
            Self::Bounded(_) => Ok(()),
            Self::Excess(count) => Err(executor::InstallError::Coordinators {
                count,
                limit: schedule::LIMIT,
            }),
        }
    }
}