about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2024-03-24 10:57:17 +0000
committerDavid Carlier <devnexen@gmail.com>2024-03-24 10:57:17 +0000
commit4b84df9ea398fd3b3da55968d021906fc2346ce8 (patch)
tree1de1166ff0f39df591ab9c556b81710e50f3f4bf /library/std
parent548e14b43963882fb758deb89e8258d9b8c2fc2a (diff)
downloadrust-4b84df9ea398fd3b3da55968d021906fc2346ce8.tar.gz
rust-4b84df9ea398fd3b3da55968d021906fc2346ce8.zip
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')
-rw-r--r--library/std/src/sys/pal/unix/thread.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs
index 6520ca9fc48..9befcb0e3e6 100644
--- a/library/std/src/sys/pal/unix/thread.rs
+++ b/library/std/src/sys/pal/unix/thread.rs
@@ -483,6 +483,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 {
+                NonZero::new(cpus as 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(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`