Skip to main content

dope_core/executor/task/context/
wake.rs

1use ready::task;
2
3use crate::driver::{
4    self,
5    schedule::ready::{self, wake},
6};
7
8/// Driver-owned wake target that cannot name a task node.
9/// The root boundary supplies it, and child contexts retain that exact root.
10/// Generational ready keys make wakes after slot release a no-op.
11#[derive(Clone, Copy)]
12pub struct RootWaker<'d> {
13    target: ready::Target<'d>,
14}
15
16impl<'d> RootWaker<'d> {
17    pub fn wake(self) {
18        self.target.wake();
19    }
20}
21
22impl<'d> From<ready::Target<'d>> for RootWaker<'d> {
23    fn from(target: ready::Target<'d>) -> Self {
24        Self { target }
25    }
26}
27
28impl<'d> From<RootWaker<'d>> for Waker<'d> {
29    fn from(root: RootWaker<'d>) -> Self {
30        Waker::from_parent(task::Parent::from(root.target))
31    }
32}
33
34#[derive(Clone, Copy, PartialEq, Eq)]
35#[repr(transparent)]
36pub struct Waker<'d>(pub(crate) task::Parent<'d>);
37
38impl<'d> Waker<'d> {
39    pub(crate) fn from_parent(parent: task::Parent<'d>) -> Self {
40        Self(parent)
41    }
42
43    /// Returns the scheduler wake capability carried by this fiber wake.
44    pub fn completion(self) -> wake::Waker<'d> {
45        self.0.into()
46    }
47
48    pub fn wake(self) {
49        self.0.wake();
50    }
51
52    pub fn belongs_to(self, driver: driver::Reference<'_>) -> bool {
53        self.0.belongs_to(driver)
54    }
55}