use libc::c_uchar;
use std::fmt;
#[repr(C)]
pub struct TopologySupport {
discovery: *const TopologyDiscoverySupport,
cpubind: *const TopologyCpuBindSupport,
membind: *const TopologyMemBindSupport,
}
impl fmt::Debug for TopologySupport {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
write!(f,
"{:?}, {:?}, {:?}",
*self.discovery,
*self.cpubind,
*self.membind)
}
}
}
impl TopologySupport {
pub fn discovery(&self) -> &TopologyDiscoverySupport {
unsafe { &*self.discovery }
}
pub fn cpu(&self) -> &TopologyCpuBindSupport {
unsafe { &*self.cpubind }
}
pub fn memory(&self) -> &TopologyMemBindSupport {
unsafe { &*self.membind }
}
}
#[repr(C)]
#[derive(Debug)]
pub struct TopologyDiscoverySupport {
pu: c_uchar,
}
impl TopologyDiscoverySupport {
pub fn pu(&self) -> bool {
self.pu == 1
}
}
#[repr(C)]
#[derive(Debug)]
pub struct TopologyCpuBindSupport {
set_thisproc_cpubind: c_uchar,
get_thisproc_cpubind: c_uchar,
set_proc_cpubind: c_uchar,
get_proc_cpubind: c_uchar,
set_thisthread_cpubind: c_uchar,
get_thisthread_cpubind: c_uchar,
set_thread_cpubind: c_uchar,
get_thread_cpubind: c_uchar,
get_thisproc_last_cpu_location: c_uchar,
get_proc_last_cpu_location: c_uchar,
get_thisthread_last_cpu_location: c_uchar,
}
impl TopologyCpuBindSupport {
pub fn set_current_process(&self) -> bool {
self.set_thisproc_cpubind == 1
}
pub fn get_current_process(&self) -> bool {
self.get_thisproc_cpubind == 1
}
pub fn set_process(&self) -> bool {
self.set_proc_cpubind == 1
}
pub fn get_process(&self) -> bool {
self.get_proc_cpubind == 1
}
pub fn set_current_thread(&self) -> bool {
self.set_thisthread_cpubind == 1
}
pub fn get_current_thread(&self) -> bool {
self.get_thisthread_cpubind == 1
}
pub fn set_thread(&self) -> bool {
self.set_thread_cpubind == 1
}
pub fn get_thread(&self) -> bool {
self.get_thread_cpubind == 1
}
pub fn get_current_process_last_cpu_location(&self) -> bool {
self.get_thisproc_last_cpu_location == 1
}
pub fn get_process_last_cpu_location(&self) -> bool {
self.get_proc_last_cpu_location == 1
}
pub fn get_current_thread_last_cpu_location(&self) -> bool {
self.get_thisthread_last_cpu_location == 1
}
}
#[repr(C)]
#[derive(Debug)]
pub struct TopologyMemBindSupport {
set_thisproc: c_uchar,
get_thisproc: c_uchar,
set_proc: c_uchar,
get_proc: c_uchar,
set_thisthread: c_uchar,
get_thisthread: c_uchar,
set_area: c_uchar,
get_area: c_uchar,
alloc: c_uchar,
firsttouch: c_uchar,
bind: c_uchar,
interleave: c_uchar,
replicate: c_uchar,
nexttouch: c_uchar,
migrate: c_uchar,
}
impl TopologyMemBindSupport {
pub fn set_current_process(&self) -> bool {
self.set_thisproc == 1
}
pub fn get_current_process(&self) -> bool {
self.get_thisproc == 1
}
pub fn set_process(&self) -> bool {
self.set_proc == 1
}
pub fn get_process(&self) -> bool {
self.get_proc == 1
}
pub fn set_current_thread(&self) -> bool {
self.set_thisthread == 1
}
pub fn get_current_thread(&self) -> bool {
self.get_thisthread == 1
}
pub fn set_area(&self) -> bool {
self.set_area == 1
}
pub fn get_area(&self) -> bool {
self.get_area == 1
}
pub fn alloc(&self) -> bool {
self.alloc == 1
}
pub fn first_touch(&self) -> bool {
self.firsttouch == 1
}
pub fn bind(&self) -> bool {
self.bind == 1
}
pub fn interleave(&self) -> bool {
self.interleave == 1
}
pub fn replicate(&self) -> bool {
self.replicate == 1
}
pub fn next_touch(&self) -> bool {
self.nexttouch == 1
}
pub fn migrate(&self) -> bool {
self.migrate == 1
}
}