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