Skip to main content

dope_sys/engine/
mod.rs

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