Skip to content

Commit

Permalink
Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviper
Browse files Browse the repository at this point in the history
std: available_parallelism using native netbsd api first

before falling back to existing code paths like FreeBSD does.
  • Loading branch information
compiler-errors authored Jun 16, 2023
2 parents c55af41 + 25b3751 commit 4d5e7cd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 4d5e7cd

Please sign in to comment.