Skip to content

Commit 8de4746

Browse files
surbangitbot
authored and
gitbot
committed
Use UNIX thread_local implementation for WASI.
1 parent 4a914fa commit 8de4746

File tree

3 files changed

+22
-75
lines changed

3 files changed

+22
-75
lines changed

std/src/sys/thread_local/guard/wasi.rs

-71
This file was deleted.

std/src/sys/thread_local/key/unix.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
use crate::mem;
22

3+
// For WASI add a few symbols not in upstream `libc` just yet.
4+
#[cfg(target_os = "wasi")]
5+
mod libc {
6+
use crate::ffi;
7+
8+
#[allow(non_camel_case_types)]
9+
pub type pthread_key_t = ffi::c_uint;
10+
11+
extern "C" {
12+
pub fn pthread_key_create(
13+
key: *mut pthread_key_t,
14+
destructor: unsafe extern "C" fn(*mut ffi::c_void),
15+
) -> ffi::c_int;
16+
#[allow(dead_code)]
17+
pub fn pthread_getspecific(key: pthread_key_t) -> *mut ffi::c_void;
18+
pub fn pthread_setspecific(key: pthread_key_t, value: *const ffi::c_void) -> ffi::c_int;
19+
pub fn pthread_key_delete(key: pthread_key_t) -> ffi::c_int;
20+
}
21+
}
22+
323
pub type Key = libc::pthread_key_t;
424

525
#[inline]

std/src/sys/thread_local/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ pub(crate) mod guard {
8585
} else if #[cfg(target_os = "windows")] {
8686
mod windows;
8787
pub(crate) use windows::enable;
88-
} else if #[cfg(all(target_os = "wasi"))] {
89-
mod wasi;
90-
pub(crate) use wasi::enable;
9188
} else if #[cfg(any(
92-
target_family = "wasm",
89+
all(target_family = "wasm", not(target_os="wasi")),
9390
target_os = "uefi",
9491
target_os = "zkvm",
9592
))] {
@@ -138,6 +135,7 @@ pub(crate) mod key {
138135
target_family = "unix",
139136
),
140137
target_os = "teeos",
138+
target_os = "wasi",
141139
))] {
142140
mod racy;
143141
mod unix;

0 commit comments

Comments
 (0)