Skip to main content

dope_sys/engine/
raw.rs

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