-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathmod.rs
More file actions
62 lines (54 loc) · 1.44 KB
/
mod.rs
File metadata and controls
62 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::sync::atomic::{AtomicU8, Ordering};
cfg_select! {
windows => {
mod iocp;
pub use iocp::*;
}
fusion => {
mod fusion;
mod poll;
mod iour;
pub use fusion::*;
}
io_uring => {
mod iour;
pub use iour::*;
}
stub => {
mod stub;
pub use stub::*;
}
unix => {
mod poll;
pub use poll::*;
}
_ => {}
}
crate::assert_not_impl!(Driver, Send);
crate::assert_not_impl!(Driver, Sync);
const IDLE: u8 = 0b00;
const NOTIFIED: u8 = 0b01;
const AWAKE: u8 = 0b10;
#[derive(Debug)]
struct AwakeFlag(AtomicU8);
impl AwakeFlag {
pub fn new() -> Self {
Self(AtomicU8::new(IDLE))
}
/// Mark the driver as awake by overwriting the flag byte with `AWAKE`.
/// This intentionally clears any previously set `NOTIFIED` flag.
/// Returns true if the `NOTIFIED` flag was set.
pub fn set(&self) -> bool {
(self.0.swap(AWAKE, Ordering::AcqRel) & NOTIFIED) != 0
}
/// Reset the flags. Returns true if it was notified.
pub fn reset(&self) -> bool {
(self.0.swap(IDLE, Ordering::AcqRel) & NOTIFIED) != 0
}
/// Set the notified flag. Returns true if the awake flag is set or the
/// notified flag is set. If the awake flag is not set, the driver needs
/// to be notified through a syscall.
pub fn wake(&self) -> bool {
self.0.fetch_or(NOTIFIED, Ordering::AcqRel) != 0
}
}