File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,29 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
344344 }
345345 }
346346
347+ #[ cfg( target_os = "netbsd" ) ]
348+ {
349+ unsafe {
350+ let set = libc:: _cpuset_create( ) ;
351+ if !set. is_null( ) {
352+ let mut count: usize = 0 ;
353+ if libc:: pthread_getaffinity_np( libc:: pthread_self( ) , libc:: _cpuset_size( set) , set) == 0 {
354+ for i in 0 ..u64 :: MAX {
355+ match libc:: _cpuset_isset( i, set) {
356+ -1 => break ,
357+ 0 => continue ,
358+ _ => count = count + 1 ,
359+ }
360+ }
361+ }
362+ libc:: _cpuset_destroy( set) ;
363+ if let Some ( count) = NonZeroUsize :: new( count) {
364+ return Ok ( count) ;
365+ }
366+ }
367+ }
368+ }
369+
347370 let mut cpus: libc:: c_uint = 0 ;
348371 let mut cpus_size = crate :: mem:: size_of_val( & cpus) ;
349372
You can’t perform that action at this time.
0 commit comments