mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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.
This commit is contained in:
parent
cb3999cd83
commit
468959580a
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user