diff options
| author | Sébastien Marie <semarie@users.noreply.github.com> | 2015-12-23 11:28:24 +0100 |
|---|---|---|
| committer | Sébastien Marie <semarie@users.noreply.github.com> | 2016-01-12 08:43:52 +0100 |
| commit | 468959580ae9bef5996ae1d43fc9d730e4977999 (patch) | |
| tree | 8ce71c91f2628ed77c41153a6b45673c414f962b /src/libtest | |
| parent | cb3999cd83a3fbfbd79aaeef3a295aff46c9ea14 (diff) | |
| download | rust-468959580ae9bef5996ae1d43fc9d730e4977999.tar.gz rust-468959580ae9bef5996ae1d43fc9d730e4977999.zip | |
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.
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 19 |
1 files changed, 18 insertions, 1 deletions
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<TestDescAndFn>) -> Vec<TestDescAndFn> { |
