about summary refs log tree commit diff
path: root/library/std/src/sys/unix/thread.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-05 06:56:57 +0000
committerbors <bors@rust-lang.org>2021-10-05 06:56:57 +0000
commit074f63648bd2368d5ca19aed02b5763a144e5d05 (patch)
treea39ab48aab1c9740253a22c9ac29b32953e97a45 /library/std/src/sys/unix/thread.rs
parenta804c4b1123ae665a8d4f726524109c49efac5b6 (diff)
parent068683baf12f61d5ffbf8a7e4858c4e0c3320f3b (diff)
downloadrust-074f63648bd2368d5ca19aed02b5763a144e5d05.tar.gz
rust-074f63648bd2368d5ca19aed02b5763a144e5d05.zip
Auto merge of #89549 - Manishearth:rollup-mhkyc16, r=Manishearth
Rollup of 12 pull requests

Successful merges:

 - #87631 (os current_exe using same approach as linux to get always the full ab…)
 - #88234 (rustdoc-json: Don't ignore impls for primitive types)
 - #88651 (Use the 64b inner:monotonize() implementation not the 128b one for aarch64)
 - #88816 (Rustdoc migrate to table so the gui can handle >2k constants)
 - #89244 (refactor: VecDeques PairSlices fields to private)
 - #89364 (rustdoc-json: Encode json files with UTF-8)
 - #89423 (Fix ICE caused by non_exaustive_omitted_patterns struct lint)
 - #89426 (bootstrap: add config option for nix patching)
 - #89462 (haiku thread affinity build fix)
 - #89482 (Follow the diagnostic output style guide)
 - #89504 (Don't suggest replacing region with 'static in NLL)
 - #89535 (fix busted JavaScript in error index generator)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/unix/thread.rs')
-rw-r--r--library/std/src/sys/unix/thread.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index 05f51a46168..5631834eca6 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -339,14 +339,18 @@ pub fn available_concurrency() -> io::Result<NonZeroUsize> {
 
             Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
         } else if #[cfg(target_os = "haiku")] {
-            let mut sinfo: libc::system_info = crate::mem::zeroed();
-            let res = libc::get_system_info(&mut sinfo);
+            // 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`
+            unsafe {
+                let mut sinfo: libc::system_info = crate::mem::zeroed();
+                let res = libc::get_system_info(&mut sinfo);
 
-            if res != libc::B_OK {
-                return Err(io::Error::last_os_error());
-            }
+                if res != libc::B_OK {
+                    return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
+                }
 
-            Ok(unsafe { NonZeroUsize::new_unchecked(sinfo.cpu_count as usize) })
+                Ok(NonZeroUsize::new_unchecked(sinfo.cpu_count as usize))
+            }
         } else {
             // FIXME: implement on vxWorks, Redox, l4re
             Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Getting the number of hardware threads is not supported on the target platform"))