Skip to main content

compio_driver/
driver_type.rs

1/// Representing underlying driver type the fusion driver is using
2#[repr(u8)]
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum DriverType {
5    /// Using `polling` driver
6    Poll,
7    /// Using `io-uring` driver
8    IoUring,
9    /// Using `iocp` driver
10    IOCP,
11}
12
13impl DriverType {
14    /// Suggest the driver type base on OpCode availability.
15    ///
16    /// This is used when the user doesn't specify a driver type, and the driver
17    /// will choose the best one based on the supported OpCodes.
18    #[cfg(fusion)]
19    pub(crate) fn suggest(additional: crate::op::OpCodeFlag) -> DriverType {
20        use crate::op::OpCodeFlag;
21
22        let flags = additional | OpCodeFlag::basic();
23
24        if flags.get_codes().all(crate::sys::is_op_supported) {
25            DriverType::IoUring
26        } else {
27            DriverType::Poll
28        }
29    }
30
31    /// Check if the current driver is `polling`
32    pub fn is_polling(&self) -> bool {
33        *self == DriverType::Poll
34    }
35
36    /// Check if the current driver is `io-uring`
37    pub fn is_iouring(&self) -> bool {
38        *self == DriverType::IoUring
39    }
40
41    /// Check if the current driver is `iocp`
42    pub fn is_iocp(&self) -> bool {
43        *self == DriverType::IOCP
44    }
45}