dope-sys 0.76.0

Typed operating-system call contracts
Documentation
use std::time;

use o3::mem;

use crate::{
    engine::{Buffer, Source, register},
    io::reactor::event,
    table::token::host,
};

type Created<S, C, G> = (
    <S as Source<C>>::Backend,
    <<S as Source<C>>::Backend as Buffer>::Context,
    <S as Create<C, G>>::Receive,
);

/// Arms a shutdown source owned outside the native engine.
pub trait Register {
    /// # Safety
    /// Retain the source's exact descriptor until engine quiescence or destruction,
    /// including when a submission is published before this method returns an error.
    unsafe fn register(&mut self, source: register::Source<'_>) -> Result<(), register::Error>;
}

/// Commits and waits while the host retains the registered operation owners.
pub trait Poll {
    type Context;
    type Error: Copy + Eq;

    /// # Safety
    /// Registered storage and kernel identities remain valid for this driver's flights.
    unsafe fn wait<'a, Tag>(
        &'a mut self,
        quota: mem::raw::Shared<'_, Tag>,
        timeout: Option<time::Duration>,
        busy: bool,
    ) -> Result<(), Self::Error>
    where
        Self::Context: 'a;
}

/// Creates the native runtime and its external receive owners in backend order.
pub trait Create<C, G>: Source<C>
where
    Self::Backend: Buffer,
{
    type Receive;
    type Error;

    /// # Safety
    /// Retain the returned buffer context alongside the backend until native
    /// quiescence and destruction, including every returned partial cleanup owner.
    unsafe fn try_new(config: &G) -> Result<Created<Self, C, G>, Self::Error>;
}

/// # Safety
/// Keep every returned part paired with this engine through native completion and reclamation.
pub unsafe trait Owner<'d, N, F, D>
where
    F: host::raw::Drain + 'd,
{
    type Report: event::Report<Event = F::Reported>;

    /// # Safety
    /// Keep the parts paired and end this loan before application I/O re-entry.
    unsafe fn parts(
        &mut self,
    ) -> (
        &mut N,
        &'d F,
        D,
        &mut Self::Report,
        &mut Option<register::Source<'d>>,
        &mut bool,
    );
}