#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct BusyPollConfig {
pub busy_poll_us: Option<u32>,
pub prefer_busy_poll: Option<bool>,
pub busy_poll_budget: Option<u16>,
}
impl BusyPollConfig {
pub fn is_active(&self) -> bool {
self.busy_poll_us.is_some()
|| self.prefer_busy_poll.is_some()
|| self.busy_poll_budget.is_some()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_inactive() {
assert!(!BusyPollConfig::default().is_active());
}
#[test]
fn any_single_knob_activates() {
let cfg = BusyPollConfig {
busy_poll_us: Some(50),
..Default::default()
};
assert!(cfg.is_active());
let cfg = BusyPollConfig {
prefer_busy_poll: Some(true),
..Default::default()
};
assert!(cfg.is_active());
let cfg = BusyPollConfig {
busy_poll_budget: Some(64),
..Default::default()
};
assert!(cfg.is_active());
}
#[test]
fn all_three_active() {
let cfg = BusyPollConfig {
busy_poll_us: Some(50),
prefer_busy_poll: Some(true),
busy_poll_budget: Some(64),
};
assert!(cfg.is_active());
}
}