Skip to content

Commit c81173c

Browse files
authored
Rollup merge of rust-lang#89462 - devnexen:haiku_thread_aff_build_fix, r=nagisa
haiku thread affinity build fix
2 parents 21407e1 + 98dde56 commit c81173c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

library/std/src/sys/unix/thread.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,18 @@ pub fn available_concurrency() -> io::Result<NonZeroUsize> {
339339

340340
Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
341341
} else if #[cfg(target_os = "haiku")] {
342-
let mut sinfo: libc::system_info = crate::mem::zeroed();
343-
let res = libc::get_system_info(&mut sinfo);
342+
// system_info cpu_count field gets the static data set at boot time with `smp_set_num_cpus`
343+
// `get_system_info` calls then `smp_get_num_cpus`
344+
unsafe {
345+
let mut sinfo: libc::system_info = crate::mem::zeroed();
346+
let res = libc::get_system_info(&mut sinfo);
344347

345-
if res != libc::B_OK {
346-
return Err(io::Error::last_os_error());
347-
}
348+
if res != libc::B_OK {
349+
return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
350+
}
348351

349-
Ok(unsafe { NonZeroUsize::new_unchecked(sinfo.cpu_count as usize) })
352+
Ok(NonZeroUsize::new_unchecked(sinfo.cpu_count as usize))
353+
}
350354
} else {
351355
// FIXME: implement on vxWorks, Redox, l4re
352356
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Getting the number of hardware threads is not supported on the target platform"))

0 commit comments

Comments
 (0)