diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-12-10 08:55:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 08:55:57 +0100 |
| commit | ce8d24139627d4154c137445e80bb66a47d87680 (patch) | |
| tree | 72139d52682bd702ceec0c0b4ea8098e169773f0 | |
| parent | b1122b5054336ec8111bfdab876118407dc4ef53 (diff) | |
| parent | 4f16640bbf88df43ac34b4c772589931d7d567d2 (diff) | |
| download | rust-ce8d24139627d4154c137445e80bb66a47d87680.tar.gz rust-ce8d24139627d4154c137445e80bb66a47d87680.zip | |
Rollup merge of #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
| -rw-r--r-- | library/std/src/sys/thread_local/key/unix.rs | 20 | ||||
| -rw-r--r-- | library/std/src/sys/thread_local/mod.rs | 5 |
2 files changed, 24 insertions, 1 deletions
diff --git a/library/std/src/sys/thread_local/key/unix.rs b/library/std/src/sys/thread_local/key/unix.rs index 28e48a750b9..b4b58b34706 100644 --- a/library/std/src/sys/thread_local/key/unix.rs +++ b/library/std/src/sys/thread_local/key/unix.rs @@ -1,5 +1,25 @@ use crate::mem; +// For WASI add a few symbols not in upstream `libc` just yet. +#[cfg(all(target_os = "wasi", target_env = "p1", target_feature = "atomics"))] +mod libc { + use crate::ffi; + + #[allow(non_camel_case_types)] + pub type pthread_key_t = ffi::c_uint; + + extern "C" { + pub fn pthread_key_create( + key: *mut pthread_key_t, + destructor: unsafe extern "C" fn(*mut ffi::c_void), + ) -> ffi::c_int; + #[allow(dead_code)] + pub fn pthread_getspecific(key: pthread_key_t) -> *mut ffi::c_void; + pub fn pthread_setspecific(key: pthread_key_t, value: *const ffi::c_void) -> ffi::c_int; + pub fn pthread_key_delete(key: pthread_key_t) -> ffi::c_int; + } +} + pub type Key = libc::pthread_key_t; #[inline] diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs index 31d3b439060..f0a13323ec9 100644 --- a/library/std/src/sys/thread_local/mod.rs +++ b/library/std/src/sys/thread_local/mod.rs @@ -86,7 +86,9 @@ pub(crate) mod guard { mod windows; pub(crate) use windows::enable; } else if #[cfg(any( - target_family = "wasm", + all(target_family = "wasm", not( + all(target_os = "wasi", target_env = "p1", target_feature = "atomics") + )), target_os = "uefi", target_os = "zkvm", ))] { @@ -135,6 +137,7 @@ pub(crate) mod key { target_family = "unix", ), target_os = "teeos", + all(target_os = "wasi", target_env = "p1", target_feature = "atomics"), ))] { mod racy; mod unix; |
