Skip to main content

dope_runtime/executor/boot/
context.rs

1use std::mem;
2
3use dope_core::driver::schedule::{app, clock, ready};
4
5use crate::executor::{boot, root};
6
7/// One startup-root poll with only its root wake, turn budget, read-only clock,
8/// and exact poll cause.
9pub struct Context<'poll, 'd: 'poll> {
10    wake: ready::Target<'d>,
11    work: app::Work<'poll, 'd>,
12    clock: clock::Clock<'poll, 'd>,
13    cause: boot::Cause,
14}
15
16impl<'poll, 'd: 'poll> Context<'poll, 'd> {
17    pub(crate) fn new(
18        wake: ready::Target<'d>,
19        work: app::Work<'poll, 'd>,
20        clock: clock::Clock<'poll, 'd>,
21        cause: boot::Cause,
22    ) -> Self {
23        Self {
24            wake,
25            work,
26            clock,
27            cause,
28        }
29    }
30
31    pub fn into_parts(
32        self,
33    ) -> (
34        ready::Target<'d>,
35        app::Work<'poll, 'd>,
36        clock::Clock<'poll, 'd>,
37        boot::Cause,
38    ) {
39        (self.wake, self.work, self.clock, self.cause)
40    }
41
42    pub fn into_poll(self) -> (root::Budget<'poll, 'd>, clock::Clock<'poll, 'd>) {
43        (root::Budget::new(self.wake, self.work), self.clock)
44    }
45}
46
47const fn assert_layout() {
48    assert!(mem::size_of::<Context<'static, 'static>>() == 5 * mem::size_of::<usize>());
49    assert!(mem::align_of::<Context<'static, 'static>>() == mem::align_of::<usize>());
50}
51
52const _: () = assert_layout();