#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct CpuIndex(u16);
impl Index for CpuIndex
{
#[inline(always)]
fn to_c_uint(&self) -> c_uint
{
self.0 as c_uint
}
}
impl CpuIndex
{
#[inline(always)]
pub fn new(value: u16) -> Self
{
CpuIndex(value)
}
pub fn number_of_possible_cpus() -> usize
{
match unsafe { numa_num_possible_cpus() }
{
x if x.is_negative() => panic!("numa_num_possible_cpus returned a negative value {}", x),
0 => panic!("numa_num_possible_cpus returned 0"),
x @ _ => x as usize,
}
}
pub fn number_of_permitted_cpus() -> usize
{
match unsafe { numa_num_task_cpus() }
{
x if x.is_negative() => panic!("numa_num_task_cpus returned a negative value {}", x),
0 => panic!("numa_num_task_cpus returned 0"),
x @ _ => x as usize,
}
}
pub fn number_of_configured_cpus() -> usize
{
match unsafe { numa_num_configured_cpus() }
{
x if x.is_negative() => panic!("numa_num_configured_cpus returned a negative value {}", x),
0 => panic!("numa_num_configured_cpus returned 0"),
x @ _ => x as usize,
}
}
pub fn node_for_cpu(&self) -> Option<NodeIndex>
{
match unsafe { numa_node_of_cpu(self.0 as c_int) }
{
-1 => match errno().0
{
::libc::EINVAL => None,
unexpected @ _ => panic!("numa_node_for_cpu set an unexpected errno {}", unexpected),
},
x if x.is_negative() => panic!("numa_num_possible_cpus returned a negative value {}", x),
value @ _ => Some(NodeIndex(value as u8))
}
}
}