@@ -353,6 +353,7 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
353
353
target_os = "hurd" ,
354
354
target_os = "linux" ,
355
355
target_os = "aix" ,
356
+ target_os = "freebsd" ,
356
357
target_vendor = "apple" ,
357
358
) ) ] {
358
359
#[ allow( unused_assignments) ]
@@ -362,9 +363,17 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
362
363
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
363
364
{
364
365
quota = cgroups:: quota( ) . max( 1 ) ;
365
- let mut set: libc:: cpu_set_t = unsafe { mem:: zeroed( ) } ;
366
+ }
367
+
368
+ #[ cfg( any( target_os = "android" , target_os = "linux" , target_os = "freebsd" ) ) ]
369
+ {
370
+ #[ cfg( not( target_os = "freebsd" ) ) ]
371
+ type cpuset = libc:: cpu_set_t;
372
+ #[ cfg( target_os = "freebsd" ) ]
373
+ type cpuset = libc:: cpuset_t;
374
+ let mut set: cpuset = unsafe { mem:: zeroed( ) } ;
366
375
unsafe {
367
- if libc:: sched_getaffinity( 0 , mem:: size_of:: <libc :: cpu_set_t >( ) , & mut set) == 0 {
376
+ if libc:: sched_getaffinity( 0 , mem:: size_of:: <cpuset >( ) , & mut set) == 0 {
368
377
let count = libc:: CPU_COUNT ( & set) as usize ;
369
378
let count = count. min( quota) ;
370
379
@@ -389,32 +398,12 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
389
398
}
390
399
}
391
400
} else if #[ cfg( any(
392
- target_os = "freebsd" ,
393
401
target_os = "dragonfly" ,
394
402
target_os = "openbsd" ,
395
403
target_os = "netbsd" ,
396
404
) ) ] {
397
405
use crate :: ptr;
398
406
399
- #[ cfg( target_os = "freebsd" ) ]
400
- {
401
- let mut set: libc:: cpuset_t = unsafe { mem:: zeroed( ) } ;
402
- unsafe {
403
- if libc:: cpuset_getaffinity(
404
- libc:: CPU_LEVEL_WHICH ,
405
- libc:: CPU_WHICH_PID ,
406
- -1 ,
407
- mem:: size_of:: <libc:: cpuset_t>( ) ,
408
- & mut set,
409
- ) == 0 {
410
- let count = libc:: CPU_COUNT ( & set) as usize ;
411
- if count > 0 {
412
- return Ok ( NonZero :: new_unchecked( count) ) ;
413
- }
414
- }
415
- }
416
- }
417
-
418
407
#[ cfg( target_os = "netbsd" ) ]
419
408
{
420
409
unsafe {
0 commit comments