Skip to main content

dope_runtime/control/
step.rs

1use std::mem;
2
3use dope_core::driver::{self, schedule::clock};
4use o3::base::cell::region;
5
6/// One linear application control step borrowed from an exact pre-park call.
7#[must_use = "dropping a control step consumes its admitted application work"]
8pub struct Step<'step, 'd: 'step> {
9    driver: driver::Context<'step, 'd>,
10}
11
12impl<'step, 'd: 'step> Step<'step, 'd> {
13    pub(crate) fn new(driver: driver::Context<'step, 'd>) -> Self {
14        Self { driver }
15    }
16
17    /// Monotonic time captured once at the beginning of the driver turn.
18    pub fn now(&self) -> clock::Moment<'d> {
19        self.driver.driver_ref().clock().now()
20    }
21
22    /// Read-only authority for the exact monotonic sample installed for this
23    /// driver turn.
24    pub fn clock(&self) -> clock::Clock<'_, 'd> {
25        self.driver.driver_ref().clock()
26    }
27
28    /// Region authority for this admitted step only.
29    pub fn region(&mut self) -> &mut region::Token<region::Identity<'d>> {
30        self.driver.region_token()
31    }
32}
33
34const fn assert_layout<'a, 'b: 'a>() {
35    assert!(mem::size_of::<Step<'a, 'b>>() == mem::size_of::<usize>());
36    assert!(mem::align_of::<Step<'a, 'b>>() == mem::align_of::<usize>());
37}
38
39const _: () = assert_layout();