about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-24 17:08:19 +0100
committerGitHub <noreply@github.com>2024-03-24 17:08:19 +0100
commitcdf86bf4430a6b068eb2acec2c5bbf4f87ee1118 (patch)
tree023271c928991b253dc6d143dd9cbc039bb6cae4 /library/std/src/sys
parentf67fb08605adb8408ae141d9f4693b94f66fd5bc (diff)
parent1871ea5710cdead66b1dfa3621f3727026185fa4 (diff)
downloadrust-cdf86bf4430a6b068eb2acec2c5bbf4f87ee1118.tar.gz
rust-cdf86bf4430a6b068eb2acec2c5bbf4f87ee1118.zip
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.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/pal/unix/thread.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs
index 6520ca9fc48..a3e1b6782e8 100644
--- a/library/std/src/sys/pal/unix/thread.rs
+++ b/library/std/src/sys/pal/unix/thread.rs
@@ -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)]
@@ -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`