Skip to content

Commit

Permalink
HW_AVAILCPU is unavailable under openbsd
Browse files Browse the repository at this point in the history
define `num_cpus()` function for openbsd that use `HW_NCPU` for grabbing
the current number of cpus that could be used.
  • Loading branch information
semarie committed Jan 12, 2016
1 parent cb3999c commit 4689595
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/libtest/lib.rs
Expand Up @@ -919,7 +919,6 @@ fn get_concurrency() -> usize {
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "bitrig",
target_os = "openbsd",
target_os = "netbsd"))]
fn num_cpus() -> usize {
let mut cpus: libc::c_uint = 0;
Expand All @@ -946,6 +945,24 @@ fn get_concurrency() -> usize {
}
cpus as usize
}

#[cfg(target_os = "openbsd")]
fn num_cpus() -> usize {
let mut cpus: libc::c_uint = 0;
let mut cpus_size = std::mem::size_of_val(&cpus);
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];

unsafe {
libc::sysctl(mib.as_mut_ptr(), 2,
&mut cpus as *mut _ as *mut _,
&mut cpus_size as *mut _ as *mut _,
0 as *mut _, 0);
}
if cpus < 1 {
cpus = 1;
}
cpus as usize
}
}

pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescAndFn> {
Expand Down

0 comments on commit 4689595

Please sign in to comment.