Skip to content

Commit cdf86bf

Browse files
authored
Rollup merge of #122992 - devnexen:available_parallelism_sol_upd, r=Amanieu
std::thread: refine available_parallelism for solaris/illumos. Rather than the system-wide available cpus fallback solution, we fetch the cpus bound to the current process.
2 parents f67fb08 + 1871ea5 commit cdf86bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/std/src/sys/pal/unix/thread.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
355355
target_os = "tvos",
356356
target_os = "linux",
357357
target_os = "macos",
358-
target_os = "solaris",
359-
target_os = "illumos",
360358
target_os = "aix",
361359
))] {
362360
#[allow(unused_assignments)]
@@ -483,6 +481,12 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
483481
.ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"))
484482
}
485483
}
484+
} else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
485+
let mut cpus = 0u32;
486+
if unsafe { libc::pset_info(libc::PS_MYID, core::ptr::null_mut(), &mut cpus, core::ptr::null_mut()) } != 0 {
487+
return Err(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"));
488+
}
489+
Ok(unsafe { NonZero::new_unchecked(cpus as usize) })
486490
} else if #[cfg(target_os = "haiku")] {
487491
// system_info cpu_count field gets the static data set at boot time with `smp_set_num_cpus`
488492
// `get_system_info` calls then `smp_get_num_cpus`

0 commit comments

Comments
 (0)