Skip to content

Commit

Permalink
Rollup merge of rust-lang#128026 - devnexen:available_parallelism_vxw…
Browse files Browse the repository at this point in the history
…orks, r=Mark-Simulacrum

std::thread: available_parallelism implementation for vxWorks proposal.
  • Loading branch information
matthiaskrgr authored Aug 5, 2024
2 parents 22e026b + 6aa00e1 commit acb2c30
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Expand Down

0 comments on commit acb2c30

Please sign in to comment.