From 468959580ae9bef5996ae1d43fc9d730e4977999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Wed, 23 Dec 2015 11:28:24 +0100 Subject: [PATCH] HW_AVAILCPU is unavailable under openbsd define `num_cpus()` function for openbsd that use `HW_NCPU` for grabbing the current number of cpus that could be used. --- src/libtest/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 2945d20ceb1..dcc344c4ffd 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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; @@ -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) -> Vec {