Skip to main content

dope_runtime/executor/drive/
error.rs

1use std::{mem, time};
2
3use dope_core::{
4    Errno,
5    driver::{life, result::poll, schedule::ready},
6};
7use poll::fault;
8
9use crate::executor::drive::{clock, regress::Regression};
10
11/// Failure while driving one executor application.
12
13#[derive(Debug)]
14pub enum Error {
15    Boot(life::Busy),
16    Capacity(ready::Capacity),
17    Poll(poll::Error),
18    Completion(fault::Dispatch),
19    Deadline(clock::Range),
20    ClockMovedBackwards(Regression),
21    TimerDisarm(Errno),
22    Shutdown,
23    QuiescenceTimeout,
24    Timeout,
25}
26
27impl Error {
28    pub(crate) const fn timeout(clock::Elapsed: clock::Elapsed) -> Self {
29        Self::Timeout
30    }
31
32    pub(crate) const fn quiesce(clock::Elapsed: clock::Elapsed) -> Self {
33        Self::QuiescenceTimeout
34    }
35}
36
37impl Error {
38    pub(crate) const fn regression(ask: time::Instant, current: time::Instant) -> Self {
39        Self::ClockMovedBackwards(Regression::new(ask, current))
40    }
41}
42
43impl From<life::Busy> for Error {
44    fn from(error: life::Busy) -> Self {
45        Self::Boot(error)
46    }
47}
48
49impl From<ready::Capacity> for Error {
50    fn from(error: ready::Capacity) -> Self {
51        Self::Capacity(error)
52    }
53}
54
55impl From<poll::Error> for Error {
56    fn from(error: poll::Error) -> Self {
57        Self::Poll(error)
58    }
59}
60
61impl From<fault::Dispatch> for Error {
62    fn from(failure: fault::Dispatch) -> Self {
63        Self::Completion(failure)
64    }
65}
66
67impl From<poll::Failure> for Error {
68    fn from(failure: poll::Failure) -> Self {
69        match failure {
70            poll::Failure::Native(error) => Self::Poll(error),
71            poll::Failure::Completion(fault) => Self::Completion(fault),
72        }
73    }
74}
75
76impl From<clock::Range> for Error {
77    fn from(range: clock::Range) -> Self {
78        Self::Deadline(range)
79    }
80}
81
82const _: () = {
83    assert!(!mem::needs_drop::<Error>());
84    assert!(
85        mem::size_of::<Error>() <= mem::size_of::<fault::Dispatch>() + mem::align_of::<Error>()
86    );
87};