File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -326,6 +326,25 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
326326 } else if #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" , target_os = "netbsd" ) ) ] {
327327 use crate :: ptr;
328328
329+ #[ cfg( target_os = "freebsd" ) ]
330+ {
331+ let mut set: libc:: cpuset_t = unsafe { mem:: zeroed( ) } ;
332+ unsafe {
333+ if libc:: cpuset_getaffinity(
334+ libc:: CPU_LEVEL_WHICH ,
335+ libc:: CPU_WHICH_PID ,
336+ -1 ,
337+ mem:: size_of:: <libc:: cpuset_t>( ) ,
338+ & mut set,
339+ ) == 0 {
340+ let count = libc:: CPU_COUNT ( & set) as usize ;
341+ if count > 0 {
342+ return Ok ( NonZeroUsize :: new_unchecked( count) ) ;
343+ }
344+ }
345+ }
346+ }
347+
329348 let mut cpus: libc:: c_uint = 0 ;
330349 let mut cpus_size = crate :: mem:: size_of_val( & cpus) ;
331350
You can’t perform that action at this time.
0 commit comments