diff options
| author | David Carlier <devnexen@gmail.com> | 2024-07-21 09:43:06 +0100 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2024-07-21 09:52:21 +0100 |
| commit | 468f9358f3f73db9a0ea6dc1a94320177718061a (patch) | |
| tree | 842ef6ff20bf4222aaab42a198896c6330bc0147 | |
| parent | a62ac152adad7811df051c4387f58594f8a74101 (diff) | |
| download | rust-468f9358f3f73db9a0ea6dc1a94320177718061a.tar.gz rust-468f9358f3f73db9a0ea6dc1a94320177718061a.zip | |
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 619f4e4121e..0f496a39173 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -462,8 +462,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")) } } |
