Skip to content

Commit 79abe24

Browse files
authored
Rollup merge of rust-lang#133472 - rust-wasi-web:master, r=joboet
Run TLS destructors for wasm32-wasip1-threads The target wasm32-wasip1-threads has support for pthreads and allows registration of TLS destructors. For spawned threads, this registers Rust TLS destructors by creating a pthreads key with an attached destructor function. For the main thread, this registers an `atexit` handler to run the TLS destructors.
2 parents ae59014 + 4fe15b0 commit 79abe24

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

library/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]

library/std/src/sys/thread_local/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub(crate) mod guard {
8686
mod windows;
8787
pub(crate) use windows::enable;
8888
} else if #[cfg(any(
89-
target_family = "wasm",
89+
all(target_family = "wasm", not(target_os="wasi")),
9090
target_os = "uefi",
9191
target_os = "zkvm",
9292
))] {
@@ -135,6 +135,7 @@ pub(crate) mod key {
135135
target_family = "unix",
136136
),
137137
target_os = "teeos",
138+
target_os = "wasi",
138139
))] {
139140
mod racy;
140141
mod unix;

0 commit comments

Comments
 (0)