Skip to content

Commit

Permalink
Rollup merge of rust-lang#122992 - devnexen:available_parallelism_sol…
Browse files Browse the repository at this point in the history
…_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.
  • Loading branch information
matthiaskrgr authored Mar 24, 2024
2 parents f67fb08 + 1871ea5 commit cdf86bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
target_os = "tvos",
target_os = "linux",
target_os = "macos",
target_os = "solaris",
target_os = "illumos",
target_os = "aix",
))] {
#[allow(unused_assignments)]
Expand Down Expand Up @@ -483,6 +481,12 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
.ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"))
}
}
} else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
let mut cpus = 0u32;
if unsafe { libc::pset_info(libc::PS_MYID, core::ptr::null_mut(), &mut cpus, core::ptr::null_mut()) } != 0 {
return Err(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"));
}
Ok(unsafe { NonZero::new_unchecked(cpus as usize) })
} else if #[cfg(target_os = "haiku")] {
// system_info cpu_count field gets the static data set at boot time with `smp_set_num_cpus`
// `get_system_info` calls then `smp_get_num_cpus`
Expand Down

0 comments on commit cdf86bf

Please sign in to comment.