about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-04 23:56:22 -0700
committerGitHub <noreply@github.com>2021-10-04 23:56:22 -0700
commita23d7f01d3d486d02fe18949d7097fd4bda27f43 (patch)
treef53e474d3342105ea2cddab315320fa73dfe2908 /library/std/src
parent94b72f4dd0beb5d2b7f7910c81c28e8101ab2c44 (diff)
parent98dde56eb1b4bc5ef03d84c77d25e094f8d66403 (diff)
downloadrust-a23d7f01d3d486d02fe18949d7097fd4bda27f43.tar.gz
rust-a23d7f01d3d486d02fe18949d7097fd4bda27f43.zip
Rollup merge of #89462 - devnexen:haiku_thread_aff_build_fix, r=nagisa
haiku thread affinity build fix
Diffstat (limited to 'library/std/src')
-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"))