Skip to main content

dope_sys/engine/
mod.rs

1use std::{ops::ControlFlow, task};
2
3use o3::{buffer, mem::slot};
4
5use crate::{io, io::reactor::event::fault, memory};
6
7pub mod admit;
8mod cancel;
9mod install;
10pub mod raw;
11pub mod register;
12pub mod ring;
13pub mod shutdown;
14pub use cancel::Cancel;
15pub use install::Install;
16
17pub type Progress<H> = (ControlFlow<H, Drain>, ControlFlow<()>);
18pub type Dispatch<H, P, F> = Result<Progress<H>, Failure<P, F>>;
19
20/// Exact completed receive ownership and its original projection context.
21pub trait Buffer {
22    type Layout: memory::raw::Layout;
23    type Token;
24    type Context: memory::Context<Layout = Self::Layout> + buffer::raw::Fixed<Self::Token>;
25    type Retained;
26    type Arena<C>;
27    type Root<'d, C>: Copy
28    where
29        C: 'd,
30        Self::Retained: 'd;
31}
32
33/// Selects the native backend owner for its host's typed contracts.
34pub trait Source<C> {
35    type Backend: io::Close<State = Self::Closing> + shutdown::Shutdown;
36    type Closing: io::Retry;
37}
38
39/// Selects retained construction and fixed-file removal owners.
40pub trait Storage<C, L, P: Copy, R: Copy>: Removal {
41    type Cleanup: memory::Cleanup<P>;
42    type Release: memory::Cleanup<(R, Self::Slot)>;
43}
44
45/// Selects the native fixed-file target retained by a failed removal.
46pub trait Removal {
47    type Slot: Copy + Eq;
48}
49
50/// Driver-local work that must be drained before blocking.
51pub trait Pending {
52    fn has_deferred(&self) -> bool;
53}
54
55/// Runs the active application's phase after each native loan has ended.
56pub trait Mode<'d, Q = (), O = ()>: Sized {
57    type Event;
58    type Held;
59    type Work: Copy;
60    type Pending<'p>
61    where
62        'd: 'p;
63
64    fn replay<'p>(
65        &mut self,
66        work: Self::Work,
67        pending: &mut Self::Pending<'p>,
68    ) -> ControlFlow<Self::Held>
69    where
70        'd: 'p;
71
72    fn emit<'p>(
73        &mut self,
74        event: slot::Occupied<'_, Self::Event>,
75        work: Self::Work,
76        pending: &mut Self::Pending<'p>,
77    ) -> ControlFlow<Self::Held>
78    where
79        'd: 'p;
80
81    fn park(&mut self);
82    fn observed(observer: &O) -> ControlFlow<()>;
83}
84
85/// Exact failure from native dispatch or completion decoding.
86#[derive(Debug, Clone, Copy, Eq, PartialEq)]
87pub enum Failure<P, F> {
88    Native(P),
89    Completion(fault::Dispatch<F>),
90}
91
92impl<P, F> From<(task::Poll<()>, F)> for Failure<P, F> {
93    fn from((state, fault): (task::Poll<()>, F)) -> Self {
94        Self::Completion(fault::Dispatch {
95            drain: state.into(),
96            fault,
97        })
98    }
99}
100
101#[derive(Clone, Copy, Eq, PartialEq, Debug)]
102#[must_use = "pending backend events must be drained before blocking"]
103pub enum Drain {
104    /// The visible event queue was empty after synchronization.
105    Drained,
106    /// Visible events require another reactor turn.
107    Pending,
108}
109
110impl From<task::Poll<()>> for Drain {
111    fn from(state: task::Poll<()>) -> Self {
112        match state {
113            task::Poll::Ready(()) => Self::Drained,
114            task::Poll::Pending => Self::Pending,
115        }
116    }
117}