File tree 1 file changed +14
-3
lines changed
library/std/src/sys/pal/wasi
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use crate :: ffi:: CStr ;
4
4
use crate :: num:: NonZero ;
5
- use crate :: sys:: unsupported;
6
5
use crate :: time:: Duration ;
7
6
use crate :: { io, mem} ;
8
7
@@ -34,6 +33,8 @@ cfg_if::cfg_if! {
34
33
#[ allow( non_camel_case_types) ]
35
34
pub type pthread_t = * mut ffi:: c_void;
36
35
36
+ pub const _SC_NPROCESSORS_ONLN: ffi:: c_int = 84 ;
37
+
37
38
extern "C" {
38
39
pub fn pthread_create(
39
40
native: * mut pthread_t,
@@ -121,7 +122,7 @@ impl Thread {
121
122
}
122
123
} else {
123
124
pub unsafe fn new( _stack: usize , _p: Box <dyn FnOnce ( ) >) -> io:: Result <Thread > {
124
- unsupported( )
125
+ crate :: sys :: unsupported( )
125
126
}
126
127
}
127
128
}
@@ -187,5 +188,15 @@ impl Thread {
187
188
}
188
189
189
190
pub 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
+ }
191
202
}
You can’t perform that action at this time.
0 commit comments