Skip to main content

dope_sys/engine/
raw.rs

1use std::{ops, task, time};
2
3use crate::{
4    engine::{Buffer, Source, life, register},
5    io::reactor::ready::{delivery, store::Quota},
6};
7
8type Created<S, C, G> = (
9    <S as Source<C>>::Backend,
10    <<S as Source<C>>::Backend as Buffer>::Context,
11    <S as Create<C, G>>::Receive,
12);
13
14/// Arms a shutdown source owned outside the native engine.
15pub trait Register {
16    /// # Safety
17    /// Retain the source's exact descriptor until engine quiescence or destruction,
18    /// including when a submission is published before this method returns an error.
19    unsafe fn register(&mut self, source: register::Source<'_>) -> Result<(), register::Error>;
20}
21
22/// Finishes native retirement and rearms the retained generation source.
23pub trait Resume<'a, R>
24where
25    R: life::Resume + 'a,
26    <R::Backend as Poll>::Context: 'a,
27{
28    /// # Safety
29    /// Retain the exact source descriptor continuously until the next native
30    /// quiescence or destruction, including when rearming publishes before an error.
31    unsafe fn try_resume(resolver: R) -> life::Retirement<R, R>;
32}
33
34/// Dispatches completions while the host retains their registered storage.
35pub trait Dispatch<'a, C, H, Q: delivery::Quota<H>>: Sized
36where
37    C: delivery::Context<H>,
38{
39    /// # Safety
40    /// Registered storage and kernel identities remain valid for this driver's flights.
41    unsafe fn new(host: &'a mut H, quota: Q) -> Self;
42
43    fn dispatch(
44        self,
45        emit: impl FnMut(C::Event, &mut H) -> ops::ControlFlow<C::Event>,
46    ) -> C::Dispatch;
47}
48
49/// Commits and waits while the host retains the registered operation owners.
50pub trait Poll {
51    type Context;
52    type Error: Copy + Eq;
53
54    /// # Safety
55    /// Registered storage and kernel identities remain valid for this driver's flights.
56    unsafe fn commit<'a, Q: Quota>(
57        &'a mut self,
58        quota: Q,
59        deferred: impl FnOnce() -> bool,
60    ) -> Result<task::Poll<()>, Self::Error>
61    where
62        Self::Context: 'a;
63
64    /// # Safety
65    /// Registered storage and kernel identities remain valid for this driver's flights.
66    unsafe fn wait<'a, Q: Quota>(
67        &'a mut self,
68        quota: Q,
69        timeout: Option<time::Duration>,
70        busy: bool,
71    ) -> Result<(), Self::Error>
72    where
73        Self::Context: 'a;
74}
75
76/// Creates the native runtime and its external receive owners in backend order.
77pub trait Create<C, G>: Source<C>
78where
79    Self::Backend: Buffer,
80{
81    type Receive;
82    type Error;
83
84    /// # Safety
85    /// Retain the returned buffer context alongside the backend until native
86    /// quiescence and destruction, including every returned partial cleanup owner.
87    unsafe fn try_new(config: &G) -> Result<Created<Self, C, G>, Self::Error>;
88}