diff options
| author | Michael Goulet <michael@errs.io> | 2023-06-16 12:53:21 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-16 12:53:21 -0700 |
| commit | 4d5e7cdc03555676f2c309cc4a3daff880ba41b1 (patch) | |
| tree | e67024d456662cd2a90c7e94ae8b0aa7acf881eb | |
| parent | c55af41e7a8388a022049f21a93b68626b36bc90 (diff) | |
| parent | 25b3751fd1585e3ce8d9806cc197f6c60f95b367 (diff) | |
| download | rust-4d5e7cdc03555676f2c309cc4a3daff880ba41b1.tar.gz rust-4d5e7cdc03555676f2c309cc4a3daff880ba41b1.zip | |
Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviper
std: available_parallelism using native netbsd api first before falling back to existing code paths like FreeBSD does.
| -rw-r--r-- | library/std/src/sys/unix/thread.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 878af5088d9..010015667f7 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -344,6 +344,29 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { } } + #[cfg(target_os = "netbsd")] + { + unsafe { + let set = libc::_cpuset_create(); + if !set.is_null() { + let mut count: usize = 0; + if libc::pthread_getaffinity_np(libc::pthread_self(), libc::_cpuset_size(set), set) == 0 { + for i in 0..u64::MAX { + match libc::_cpuset_isset(i, set) { + -1 => break, + 0 => continue, + _ => count = count + 1, + } + } + } + libc::_cpuset_destroy(set); + if let Some(count) = NonZeroUsize::new(count) { + return Ok(count); + } + } + } + } + let mut cpus: libc::c_uint = 0; let mut cpus_size = crate::mem::size_of_val(&cpus); |
