Skip to main content

dope_runtime/process/failure/
bus.rs

1use std::mem;
2
3pub use dope_core::dope_sys::io::socket::record::Error as Create;
4use dope_core::platform::affinity;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7#[repr(u8)]
8pub enum Event {
9    Installed,
10    Ready,
11    Drain,
12    Done,
13    Failed,
14}
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17#[repr(transparent)]
18pub struct Invalid(u8);
19
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21pub struct RecordSize {
22    pub expected: usize,
23    pub actual: usize,
24}
25
26#[derive(Debug)]
27pub struct Startup {
28    pub cpu: affinity::Cpu,
29    pub event: Event,
30    pub workers: usize,
31    pub installed: usize,
32    pub ready: usize,
33    pub gated: bool,
34}
35
36#[derive(Debug)]
37pub struct Drain {
38    pub cause: DrainCause,
39    pub workers: usize,
40    pub drained: usize,
41    pub done: usize,
42}
43
44#[derive(Debug)]
45pub enum DrainCause {
46    Event { cpu: affinity::Cpu, event: Event },
47    Order,
48}
49
50#[derive(Debug)]
51pub struct Shutdown {
52    pub cpu: affinity::Cpu,
53    pub event: Event,
54    pub workers: usize,
55    pub done: usize,
56}
57
58impl Event {
59    pub(in crate::process) const fn encode(self) -> u8 {
60        self as u8
61    }
62
63    pub(in crate::process) const fn decode(value: u8) -> Result<Self, Invalid> {
64        match value {
65            0 => Ok(Self::Installed),
66            1 => Ok(Self::Ready),
67            2 => Ok(Self::Drain),
68            3 => Ok(Self::Done),
69            4 => Ok(Self::Failed),
70            value => Err(Invalid(value)),
71        }
72    }
73}
74
75#[derive(Clone, Copy, Debug, PartialEq, Eq)]
76pub enum Write {
77    Syscall(dope_core::Errno),
78    Record(RecordSize),
79}
80
81#[derive(Clone, Copy, Debug, PartialEq, Eq)]
82pub struct Fault {
83    pub event: Event,
84    pub failure: Write,
85    pub shutdown: Option<dope_core::Errno>,
86}
87
88#[derive(Debug)]
89pub enum Report {
90    Clean,
91    Failed(Fault),
92}
93
94#[derive(Debug)]
95pub struct Sequence {
96    pub gated: bool,
97    pub previous: Option<Event>,
98    pub event: Event,
99}
100
101#[derive(Debug)]
102pub enum Read {
103    Syscall(dope_core::Errno),
104    /// The coordinator consumed this Main after an exact shutdown failure.
105    Stopped(dope_core::Errno),
106    Closed,
107    Event(Invalid),
108    Sequence(Sequence),
109}
110
111#[derive(Debug)]
112pub enum State {
113    StartupEvent(Startup),
114    RuntimeEvent { cpu: affinity::Cpu, event: Event },
115    DrainEvent(Drain),
116    DrainOrder(Drain),
117    ShutdownEvent(Shutdown),
118}
119
120const _: () = {
121    assert!(mem::size_of::<Event>() == mem::size_of::<u8>());
122    assert!(mem::size_of::<Invalid>() == mem::size_of::<u8>());
123};