about summary refs log tree commit diff
path: root/library/std/src/sys_common/thread_local_key.rs
AgeCommit message (Collapse)AuthorLines
2024-06-15std: refactor the TLS implementationjoboet-174/+0
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-04-07sys_common::thread_local_key: make a note that this is not used on WindowsRalf Jung-1/+4
2024-03-19SeqCst->{Release,Acquire} in sys_common::thread_local_key.Mara Bos-3/+3
SeqCst is unnecessary here.
2023-04-27Remove unused std::sys_common::thread_local_key::Key.Mara Bos-61/+0
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-2/+8
Co-authored-by: gh-tr <troach@qnx.com>
2022-12-06Make sentinel value configurableFlorian Bartels-8/+17
There are OSs that always return the lowest free value. The algorithm in `lazy_init` always avoids keys with the sentinel value. In affected OSs, this means that each call to `lazy_init` will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards. By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue.
2022-10-08std: optimize TLS on Windowsjoboet-23/+1
2022-08-22update and extend some comments, and cfg-out some unused codeRalf Jung-0/+2
2022-05-30Remove "sys isn't exported yet" phraseest31-1/+1
The oldest occurence is from 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7, which is from the pre-1.0 days. In the years since then, std::sys still hasn't been exported, and the last attempt was met with strong criticism: https://github.com/rust-lang/rust/pull/97151 Thus, removing the "yet" part makes a lot of sense.
2020-12-22Migrate standard library away from compare_and_swapLinus Färnstrand-4/+4
2020-09-27Split sys_common::Mutex in StaticMutex and MovableMutex.Mara Bos-2/+2
The (unsafe) Mutex from sys_common had a rather complicated interface. You were supposed to call init() manually, unless you could guarantee it was neither moved nor used reentrantly. Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if destroy() should only be called when `init()` was called. This allowed for a number of interesting (confusing?) different ways to use this Mutex, all captured in a single type. In practice, this type was only ever used in two ways: 1. As a static variable. In this case, neither init() nor destroy() are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the LockGuard, never with raw_lock. 2. As a Boxed variable. In this case, both init() and destroy() are called, it will be moved and possibly used reentrantly. No other combinations are used anywhere in `std`. This change simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. The interface of both new types is now both safer and simpler. The first one does not call nor expose init/destroy, and the second one calls those automatically in its new() and Drop functions. Also, the locking functions of MovableMutex are no longer unsafe.
2020-09-22Update library functions with stability attributesDylan MacKenzie-0/+1
This may not be strictly minimal, but all unstable functions also need a `rustc_const_unstable` attribute.
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-38/+3
Also doing fmt inplace as requested.
2020-07-27mv std libs to library/mark-0/+271