Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions library/std/src/sys/pal/wasi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::ffi::CStr;
use crate::num::NonZero;
use crate::sys::unsupported;
use crate::time::Duration;
use crate::{io, mem};

Expand Down Expand Up @@ -34,6 +33,8 @@ cfg_if::cfg_if! {
#[allow(non_camel_case_types)]
pub type pthread_t = *mut ffi::c_void;

pub const _SC_NPROCESSORS_ONLN: ffi::c_int = 84;

extern "C" {
pub fn pthread_create(
native: *mut pthread_t,
Expand Down Expand Up @@ -121,7 +122,7 @@ impl Thread {
}
} else {
pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>) -> io::Result<Thread> {
unsupported()
crate::sys::unsupported()
}
}
}
Expand Down Expand Up @@ -187,5 +188,14 @@ impl Thread {
}

pub fn available_parallelism() -> io::Result<NonZero<usize>> {
unsupported()
cfg_if::cfg_if! {
if #[cfg(target_feature = "atomics")] {
match unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) } {
-1 => Err(io::Error::last_os_error()),
cpus => NonZero::new(cpus as usize).ok_or(io::Error::UNKNOWN_THREAD_COUNT),
}
} else {
crate::sys::unsupported()
}
}
}
Loading