use crate::Result;
#[cfg(all(target_os = "linux", target_env = "gnu"))]
#[path = "linux_gnu.rs"]
mod os;
#[cfg(all(target_os = "linux", not(target_env = "gnu")))]
#[path = "linux_other.rs"]
mod os;
#[cfg(not(target_os = "linux"))]
#[path = "unsupported.rs"]
mod os;
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct Params {
priority: Option<i32>,
scheduling: Scheduling,
cpu_ids: Vec<usize>,
}
impl Params {
pub fn new() -> Self {
Self::default()
}
pub fn with_priority(mut self, priority: Option<i32>) -> Self {
self.priority = priority;
self
}
pub fn with_scheduling(mut self, scheduling: Scheduling) -> Self {
self.scheduling = scheduling;
self
}
pub fn with_cpu_ids(mut self, cpu_ids: &[usize]) -> Self {
self.cpu_ids = cpu_ids.to_vec();
self
}
pub fn priority(&self) -> Option<i32> {
self.priority
}
pub fn scheduling(&self) -> Scheduling {
self.scheduling
}
pub fn cpu_ids(&self) -> &[usize] {
&self.cpu_ids
}
}
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub enum Scheduling {
RoundRobin,
FIFO,
Idle,
Batch,
DeadLine,
#[default]
Other,
}
#[inline]
pub fn apply_for_current(params: &Params) -> Result<()> {
os::apply_for_current(params)
}
#[inline]
pub fn apply(tid: libc::c_int, params: &Params) -> Result<()> {
os::apply(tid, params)
}
#[inline]
pub fn preallocate_heap(size: usize) -> Result<()> {
os::prealloc_heap(size)
}