diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-05 08:22:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-05 08:22:21 +0200 |
| commit | 02c3837d8b74ea3afc0e51da1f743b8f5fef759b (patch) | |
| tree | 396543ee2c88b93263395a7a0c98d05fab803589 | |
| parent | 176e5452095444815207be02c16de0b1487a1b53 (diff) | |
| parent | 468f9358f3f73db9a0ea6dc1a94320177718061a (diff) | |
| download | rust-02c3837d8b74ea3afc0e51da1f743b8f5fef759b.tar.gz rust-02c3837d8b74ea3afc0e51da1f743b8f5fef759b.zip | |
Rollup merge of #128026 - devnexen:available_parallelism_vxworks, r=Mark-Simulacrum
std::thread: available_parallelism implementation for vxWorks proposal.
| -rw-r--r-- | library/std/src/sys/pal/unix/thread.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 83034761f3d..44cb7b7b7ce 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -455,8 +455,18 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> { Ok(NonZero::new_unchecked(sinfo.cpu_count as usize)) } + } else if #[cfg(target_os = "vxworks")] { + // Note: there is also `vxCpuConfiguredGet`, closer to _SC_NPROCESSORS_CONF + // expectations than the actual cores availability. + extern "C" { + fn vxCpuEnabledGet() -> libc::cpuset_t; + } + + // always fetches a valid bitmask + let set = unsafe { vxCpuEnabledGet() }; + Ok(NonZero::new_unchecked(set.count_ones() as usize)) } else { - // FIXME: implement on vxWorks, Redox, l4re + // FIXME: implement on Redox, l4re Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform")) } } |
