-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathmod.rs
More file actions
64 lines (55 loc) · 1.69 KB
/
mod.rs
File metadata and controls
64 lines (55 loc) · 1.69 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
63
64
use std::sync::atomic::{AtomicU8, Ordering};
cfg_if::cfg_if! {
if #[cfg(windows)] {
mod iocp;
pub use iocp::*;
} else if #[cfg(fusion)] {
mod fusion;
mod poll;
mod iour;
pub use fusion::*;
} else if #[cfg(io_uring)] {
mod iour;
pub use iour::*;
} else if #[cfg(stub)] {
mod stub;
pub use stub::*;
} else if #[cfg(unix)] {
mod poll;
pub use poll::*;
}
}
crate::assert_not_impl!(Driver, Send);
crate::assert_not_impl!(Driver, Sync);
/// An operation that can be optimized by making use of the "poll-first"
/// feature.
pub trait PollFirst {
/// Poll first before syscall. This is only meaningful for io-uring. It sets
/// `IORING_RECVSEND_POLL_FIRST` flag in the `ioprio` of the SQE.
fn poll_first(&mut self);
}
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.
pub fn set(&self) {
self.0.store(AWAKE, Ordering::Release);
}
/// 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
}
}