Skip to content

Commit 5866fdf

Browse files
fmeasegitbot
authored and
gitbot
committed
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. try-job: test-various
2 parents b59baf0 + 765993c commit 5866fdf

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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(all(target_os = "wasi", target_env = "p1", target_feature = "atomics"))]
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ 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(
90+
all(target_os = "wasi", target_env = "p1", target_feature = "atomics")
91+
)),
9092
target_os = "uefi",
9193
target_os = "zkvm",
9294
))] {
@@ -135,6 +137,7 @@ pub(crate) mod key {
135137
target_family = "unix",
136138
),
137139
target_os = "teeos",
140+
all(target_os = "wasi", target_env = "p1", target_feature = "atomics"),
138141
))] {
139142
mod racy;
140143
mod unix;

0 commit comments

Comments
 (0)