summary refs log tree commit diff
path: root/library/std/src/sys/thread_local
AgeCommit message (Collapse)AuthorLines
2025-02-13std: Apply unsafe_attr_outside_unsafeEric Huss-2/+2
2025-02-09Mark extern blocks as unsafeMichael Goulet-4/+4
2025-02-09Mark link_section attr with unsafeMichael Goulet-1/+1
2024-12-10Rollup merge of #133472 - rust-wasi-web:master, r=joboetLeón Orell Valerian Liehr-1/+24
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
2024-12-05Add libc funcitons only for wasm32-wasip1-threads.Sebastian Urban-1/+1
2024-12-05Fix compilation for wasm32-wasip1 (without threads).Sebastian Urban-2/+4
2024-12-03Use UNIX thread_local implementation for WASI.Sebastian Urban-75/+22
2024-11-27update cfgsBoxy-2/+0
2024-11-25Run TLS destructors for wasm32-wasip1-threadsSebastian Urban-0/+74
The target has support for pthreads and allows registration of TLS destructors.
2024-11-02Remove unintended linkHoutamelo-1/+1
Since `#[link_section]` is enclosed in braces, it was being confused with a link during docs compilation.
2024-10-25Re-do recursive const stability checksRalf Jung-2/+2
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-25Avoid use imports in thread_local_inner! in statikJeong YunWon-5/+4
Fixes #131863 for wasm targets All other macros were done in #131866, but this sub module is missed.
2024-10-18Avoid shadowing user provided types or type aliases in `thread_local!`许杰友 Jieyou Xu (Joe)-22/+26
By using qualified imports, i.e. `$crate::...::LocalKey`.
2024-10-02std: make `thread::current` available in all `thread_local!` destructorsjoboet-26/+175
2024-09-25Use `&raw` in the standard libraryJosh Stone-1/+1
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-15/+12
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-5/+5
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-20Remove _tls_used hackChris Denton-13/+0
2024-07-15Remove DWORDChris Denton-4/+4
2024-07-15Remove LPVOIDChris Denton-2/+3
2024-06-28std: add safety commentsjoboet-4/+16
2024-06-25std: separate TLS key creation from TLS accessjoboet-125/+100
Currently, `std` performs an atomic load to get the OS key on every access to `StaticKey` even when the key is already known. This PR thus replaces `StaticKey` with the platform-specific `get` and `set` function and a new `LazyKey` type that acts as a `LazyLock<Key>`, allowing the reuse of the retreived key for multiple accesses.
2024-06-24std: fix wasm buildsjoboet-2/+16
2024-06-17std: rename module for clarityjoboet-2/+2
2024-06-17std: update TLS module documentationjoboet-16/+22
2024-06-17std: use the `c_int` from `core::ffi` instead of `libc`joboet-1/+1
2024-06-17std: simplify `#[cfg]`s for TLSjoboet-15/+10
2024-06-15std: refactor the TLS implementationjoboet-26/+1065
As discovered by Mara in #110897, our TLS implementation is a total mess. In the past months, I have simplified the actual macros and their expansions, but the majority of the complexity comes from the platform-specific support code needed to create keys and register destructors. In keeping with #117276, I have therefore moved all of the `thread_local_key`/`thread_local_dtor` modules to the `thread_local` module in `sys` and merged them into a new structure, so that future porters of `std` can simply mix-and-match the existing code instead of having to copy the same (bad) implementation everywhere. The new structure should become obvious when looking at `sys/thread_local/mod.rs`. Unfortunately, the documentation changes associated with the refactoring have made this PR rather large. That said, this contains no functional changes except for two small ones: * the key-based destructor fallback now, by virtue of sharing the implementation used by macOS and others, stores its list in a `#[thread_local]` static instead of in the key, eliminating one indirection layer and drastically simplifying its code. * I've switched over ZKVM (tier 3) to use the same implementation as WebAssembly, as the implementation was just a way worse version of that Please let me know if I can make this easier to review! I know these large PRs aren't optimal, but I couldn't think of any good intermediate steps. @rustbot label +A-thread-locals
2024-06-04Auto merge of #125525 - joboet:tls_accessor, r=cuviperbors-172/+103
Make TLS accessors closures that return pointers The current TLS macros generate a function that returns an `Option<&'static T>`. This is both risky as we lie about lifetimes, and necessitates that those functions are `unsafe`. By returning a `*const T` instead, the accessor function do not have safety requirements any longer and can be made closures without hassle. This PR does exactly that! For native TLS, the closure approach makes it trivial to select the right accessor function at compile-time, which could result in a slight speed-up (I have the hope that the accessors are now simple enough for the MIR-inliner to kick in).
2024-06-02typo: depending from -> onRalf Jung-1/+1
2024-05-25std: make TLS accessors closures that return pointersjoboet-172/+103
2024-05-24std: clean up the TLS implementationjoboet-3/+4
2024-05-24std: simplify key-based thread localsjoboet-185/+60
2024-05-24Auto merge of #123724 - joboet:static_tls, r=m-ou-sebors-70/+76
Rewrite TLS on platforms without threads The saga of #110897 continues! r? `@m-ou-se` if you have time
2024-05-23std: rewrite native thread-local storagejoboet-248/+330
2024-04-30std: rewrite TLS on platforms without threadsjoboet-70/+76
2024-04-26thread_local: refine LazyKeyInner::take safety docJubilee-1/+1
Co-authored-by: joboet <jonasboettiger@icloud.com>
2024-04-25thread_local: split refs to fields of KeyJubilee Young-3/+4
2024-04-25thread_local: use less &mut T in LazyKeyInner::takeJubilee Young-6/+8
Instead, use raw pointers to accomplish internal mutability throughout.
2024-04-15static_mut_refs: use raw pointers to remove the remaining FIXMERalf Jung-3/+2
2024-03-20step cfgsMark Rousskov-2/+1
2024-03-16Use `UnsafeCell` for fast constant thread localsJohn Kåre Alsaker-8/+7
2024-02-28std: move thread local implementation to `sys`joboet-0/+664