Skip to content

Commit 02c3837

Browse files
authored
Rollup merge of rust-lang#128026 - devnexen:available_parallelism_vxworks, r=Mark-Simulacrum
std::thread: available_parallelism implementation for vxWorks proposal.
2 parents 176e545 + 468f935 commit 02c3837

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,18 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
455455

456456
Ok(NonZero::new_unchecked(sinfo.cpu_count as usize))
457457
}
458+
} else if #[cfg(target_os = "vxworks")] {
459+
// Note: there is also `vxCpuConfiguredGet`, closer to _SC_NPROCESSORS_CONF
460+
// expectations than the actual cores availability.
461+
extern "C" {
462+
fn vxCpuEnabledGet() -> libc::cpuset_t;
463+
}
464+
465+
// always fetches a valid bitmask
466+
let set = unsafe { vxCpuEnabledGet() };
467+
Ok(NonZero::new_unchecked(set.count_ones() as usize))
458468
} else {
459-
// FIXME: implement on vxWorks, Redox, l4re
469+
// FIXME: implement on Redox, l4re
460470
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))
461471
}
462472
}

0 commit comments

Comments
 (0)