dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
use std::num::NonZero;

use o3::mem::{lease, quota};

use crate::driver::{
    schedule,
    schedule::{app, app::batch, state::lanes},
};

pub mod raw;

/// Quota reserved for one batch before its actual size is known.
#[must_use = "dropping a batch reservation returns all of its quota"]
pub struct Reserved<'turn, 'd, T> {
    quota: quota::Shared<'turn, lanes::Domain<'d>, lease::Open>,
    limit: T,
}

impl<'turn, 'd, T: batch::raw::Limit> Reserved<'turn, 'd, T> {
    pub fn reserve(work: app::Work<'turn, 'd>, limit: T, prior: bool) -> schedule::Capacity<Self> {
        let reserved = limit.get().get() - 1 + usize::from(prior);
        match quota::Shared::reserve(&work.state.lanes.app, reserved) {
            Some(quota) => schedule::Capacity::Available(Self { quota, limit }),
            None => schedule::Capacity::Exhausted,
        }
    }

    pub fn get(&self) -> &T {
        &self.limit
    }

    pub fn empty(self) -> Reserved<'turn, 'd, ()> {
        // SAFETY: no batch item was produced under this reservation.
        unsafe { self.take(0) }
    }
}

const _: () = {
    let word = size_of::<usize>();
    assert!(size_of::<Reserved<'static, 'static, NonZero<usize>>>() == 3 * word);
    assert!(size_of::<Reserved<'static, 'static, ()>>() == 2 * word);
};