Skip to main content

dope_core/executor/raw/
mod.rs

1//! Raw application boundary. [`App`] owns complete lifecycle traversal;
2//! runtime-owned session roots choose when it may run.
3use std::{num::NonZero, ops::ControlFlow, pin};
4
5use crate::driver::{self, schedule};
6use o3::base::{cell::region, num::bounded::U32};
7
8use crate::executor;
9
10mod app;
11mod owner;
12mod plan;
13mod progress;
14
15pub use crate::io::event::{Dispatch, Occupied};
16pub use app::{App, Layout};
17pub(crate) use owner::{Backing, Draining, Live, Owner, View};
18pub use plan::{Census, Flat, Plan, Sweep};
19pub use progress::Progress;
20
21/// Cooperative drain while the complete application remains installed.
22///
23/// # Safety
24/// Preserve every admitted owner's identity, presence, address, and routes through
25/// finish. `begin` and `force` must not replace owners or reclaim retained storage.
26/// Cooperative quiescence does not authorize reclamation: the runtime still
27/// shuts down every admitted owner and drains native operations before finish.
28pub unsafe trait Drain<'d>: executor::raw::App<'d> {
29    fn begin(
30        self: pin::Pin<&mut Self>,
31        turn: schedule::Turn<'_, 'd>,
32        driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
33    );
34
35    /// Reports drain work after the application's pre-park traversal.
36    /// `Runnable` requires another turn for work that can proceed now;
37    /// `Waiting` retains the external wake or deadline needed to proceed.
38    /// `Quiescent` reports completed cooperative drain, not reclaimed owners.
39    /// The runtime combines this signal with application progress before waiting.
40    fn progress(
41        self: pin::Pin<&Self>,
42        region: &region::Token<region::Identity<'d>>,
43        state: Option<&mut schedule::Waits<'d>>,
44    ) -> ControlFlow<()>;
45
46    fn force(
47        self: pin::Pin<&mut Self>,
48        turn: schedule::Turn<'_, 'd>,
49        driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
50    );
51}
52
53/// One complete coordinator count classified at installation.
54#[derive(Clone, Copy, Debug)]
55pub enum Count {
56    Bounded(U32<0, { schedule::LIMIT as u32 }>),
57    Excess(NonZero<usize>),
58}
59
60impl Count {
61    pub const fn new(value: usize) -> Self {
62        match U32::from_usize(value) {
63            Some(value) => Self::Bounded(value),
64            None => Self::Excess(NonZero::<usize>::MIN.saturating_add(value - 1)),
65        }
66    }
67
68    pub const fn get(self) -> usize {
69        match self {
70            Self::Bounded(value) => value.into_usize(),
71            Self::Excess(value) => value.get(),
72        }
73    }
74
75    pub(in crate::executor::raw) fn admit<E>(self) -> Result<(), executor::InstallError<E>> {
76        match self {
77            Self::Bounded(_) => Ok(()),
78            Self::Excess(count) => Err(executor::InstallError::Coordinators {
79                count,
80                limit: schedule::LIMIT,
81            }),
82        }
83    }
84}