Skip to main content

dope_sys/engine/admit/
mod.rs

1mod context;
2mod guard;
3mod options;
4pub mod raw;
5mod reserve;
6
7pub use context::Context;
8pub use guard::Guard;
9pub use options::Options;
10pub use reserve::Reserve;
11
12use crate::io::reactor::Full;
13
14/// Reserves native capacity without consuming the host's operation ownership.
15pub trait Admit<C: Context>: Sized {
16    type Admission<'a>: Guard<C> + raw::Retain<C>
17    where
18        Self: 'a;
19
20    fn try_admit(&mut self) -> Result<Self::Admission<'_>, Full>;
21}
22
23/// A key-bound cancellation whose native preparation has already succeeded.
24pub trait Submission: Sized {
25    fn submit(self) -> Cancelled;
26}
27
28/// Class-specific native admission chosen entirely through its GAT.
29pub trait Plan {
30    type Guard<'a, C: Context, B: Backend<C> + 'a>: Reserve<'a, C, B>;
31}
32
33/// Selects a pending work family without a runtime class token.
34pub struct Pending<const FAMILY: u8>;
35/// Synchronous work may already own a completion in the native queue.
36pub struct Immediate;
37
38pub trait Backend<C: Context>: Sized {
39    type Pending<'a, const FAMILY: u8>: Reserve<'a, C, Self>
40    where
41        Self: 'a;
42    type Immediate<'a>: Reserve<'a, C, Self>
43    where
44        Self: 'a;
45}
46
47impl<const FAMILY: u8> Plan for Pending<FAMILY> {
48    type Guard<'a, C: Context, B: Backend<C> + 'a> = B::Pending<'a, FAMILY>;
49}
50
51impl Plan for Immediate {
52    type Guard<'a, C: Context, B: Backend<C> + 'a> = B::Immediate<'a>;
53}
54
55#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56pub enum Cancelled {
57    Submitted,
58    Queued,
59    Completed,
60}
61
62/// The native queue does not own the requested completion.
63#[derive(Clone, Copy, Debug, Eq, PartialEq)]
64pub struct Absent;
65
66/// The reserved native cancellation command was submitted.
67#[derive(Clone, Copy, Debug, Eq, PartialEq)]
68pub struct Submitted;
69
70/// Host-independent native cancellation failure domain.
71pub trait Native {
72    type Error<F>;
73}
74
75/// Native preparation failed without changing the requested operation.
76#[derive(Clone, Copy, Debug, Eq, PartialEq)]
77pub enum Cause<F> {
78    Absent(Absent),
79    Reactor(F),
80}
81
82/// Queue exhaustion and rejected native state have distinct recovery paths.
83#[derive(Clone, Copy, Debug, Eq, PartialEq)]
84pub enum Error<E> {
85    Full(Full),
86    Rejected(E),
87}