1 //! Helper module which helps to determine amount of threads to be used
2 //! during tests execution.
6 pub fn get_concurrency() -> usize {
7 return match env::var("RUST_TEST_THREADS") {
9 let opt_n: Option<usize> = s.parse().ok();
11 Some(n) if n > 0 => n,
12 _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s),
15 Err(..) => num_cpus(),
21 #[allow(nonstandard_style)]
22 fn num_cpus() -> usize {
25 wProcessorArchitecture: u16,
28 lpMinimumApplicationAddress: *mut u8,
29 lpMaximumApplicationAddress: *mut u8,
30 dwActiveProcessorMask: *mut u8,
31 dwNumberOfProcessors: u32,
33 dwAllocationGranularity: u32,
35 wProcessorRevision: u16,
38 fn GetSystemInfo(info: *mut SYSTEM_INFO) -> i32;
41 let mut sysinfo = std::mem::zeroed();
42 GetSystemInfo(&mut sysinfo);
43 sysinfo.dwNumberOfProcessors as usize
47 target_os = "android",
48 target_os = "cloudabi",
49 target_os = "emscripten",
50 target_os = "fuchsia",
54 target_os = "solaris",
55 target_os = "illumos",
57 fn num_cpus() -> usize {
58 unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize }
60 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] {
61 fn num_cpus() -> usize {
64 let mut cpus: libc::c_uint = 0;
65 let mut cpus_size = std::mem::size_of_val(&cpus);
68 cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
71 let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
76 &mut cpus as *mut _ as *mut _,
77 &mut cpus_size as *mut _ as *mut _,
88 } else if #[cfg(target_os = "openbsd")] {
89 fn num_cpus() -> usize {
92 let mut cpus: libc::c_uint = 0;
93 let mut cpus_size = std::mem::size_of_val(&cpus);
94 let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
100 &mut cpus as *mut _ as *mut _,
101 &mut cpus_size as *mut _ as *mut _,
112 // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re
113 fn num_cpus() -> usize {