diff options
| author | David Carlier <devnexen@gmail.com> | 2023-06-02 22:18:11 +0100 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2023-06-06 06:34:27 +0100 |
| commit | 25b3751fd1585e3ce8d9806cc197f6c60f95b367 (patch) | |
| tree | 6a3c926feafe07ef23717833fb35858e1ce141f1 /library/std | |
| parent | fd9bf594366e73efb1a26a023e0b4de8eff82b94 (diff) | |
| download | rust-25b3751fd1585e3ce8d9806cc197f6c60f95b367.tar.gz rust-25b3751fd1585e3ce8d9806cc197f6c60f95b367.zip | |
std: available_parallelism using native netbsd api first
before falling back to existing code paths like FreeBSD does.
Diffstat (limited to 'library/std')
| -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); |
