This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
library/std/src/sys/pal/wasi Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 22
33use crate :: ffi:: CStr ;
44use crate :: num:: NonZero ;
5- use crate :: sys:: unsupported;
65use crate :: time:: Duration ;
76use crate :: { io, mem} ;
87
@@ -34,6 +33,8 @@ cfg_if::cfg_if! {
3433 #[ allow( non_camel_case_types) ]
3534 pub type pthread_t = * mut ffi:: c_void;
3635
36+ pub const _SC_NPROCESSORS_ONLN: ffi:: c_int = 84 ;
37+
3738 extern "C" {
3839 pub fn pthread_create(
3940 native: * mut pthread_t,
@@ -121,7 +122,7 @@ impl Thread {
121122 }
122123 } else {
123124 pub unsafe fn new( _stack: usize , _p: Box <dyn FnOnce ( ) >) -> io:: Result <Thread > {
124- unsupported( )
125+ crate :: sys :: unsupported( )
125126 }
126127 }
127128 }
@@ -187,5 +188,15 @@ impl Thread {
187188}
188189
189190pub fn available_parallelism ( ) -> io:: Result < NonZero < usize > > {
190- unsupported ( )
191+ cfg_if:: cfg_if! {
192+ if #[ cfg( target_feature = "atomics" ) ] {
193+ match unsafe { libc:: sysconf( libc:: _SC_NPROCESSORS_ONLN) } {
194+ -1 => Err ( io:: Error :: last_os_error( ) ) ,
195+ 0 => Err ( io:: Error :: UNKNOWN_THREAD_COUNT ) ,
196+ cpus => Ok ( unsafe { NonZero :: new_unchecked( cpus as usize ) } ) ,
197+ }
198+ } else {
199+ crate :: sys:: unsupported( )
200+ }
201+ }
191202}
You can’t perform that action at this time.
0 commit comments