rust/library
Matthias Krüger 22060f20ae
Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-se
Make sentinel value configurable in `library/std/src/sys_common/thread_local_key.rs`

This is an excerpt of a changeset for the QNX/Neutrino OS. To make the patch for QNX smaller and easier to review, I've extracted this change (which is OS independent). I would be surprised if no other OS is also affected.

All this patch does is to define a `const` for a sentinel value instead of using it directly at several places.

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.

On QNX/Neutrino, it is planned to use a different sentinel value:
```rust
// Define a sentinel value that is unlikely to be returned
// as a TLS key (but it may be returned).
#[cfg(not(target_os = "nto"))]
const KEY_SENTVAL: usize = 0;
// On QNX/Neutrino, 0 is always returned when currently not in use.
// Using 0 would mean to always create two keys and remote the first
// one (with value of 0) immediately afterwards.
#[cfg(target_os = "nto")]
const KEY_SENTVAL: usize = libc::PTHREAD_KEYS_MAX + 1;
```

It seems like no other OS defines `PTHREAD_KEYS_MAX` in Rusts libc, but `limits.h` on unix systems does.
2022-12-28 22:22:18 +01:00
..
alloc Rollup merge of #105484 - nbdd0121:upcast, r=compiler-errors 2022-12-28 15:51:41 +08:00
backtrace@07872f28cd Update backtrace 2022-09-02 16:09:58 -04:00
core Rollup merge of #106172 - estebank:suggest-impl-trait, r=compiler-errors 2022-12-28 14:40:00 +01:00
panic_abort Remove std's transitive dependency on cfg-if 0.1 2022-11-02 18:01:20 -04:00
panic_unwind Rollup merge of #103989 - arlosi:arm32-panic, r=Amanieu 2022-11-19 15:35:20 +01:00
portable-simd Fix rustdoc lints 2022-11-06 17:21:22 -05:00
proc_macro Add a "the" to proc_macro documentation 2022-12-12 16:19:18 +01:00
profiler_builtins Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rtstartup Remove custom frame info registration on i686-pc-windows-gnu 2022-08-23 16:12:58 +08:00
rustc-std-workspace-alloc Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-core Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-std Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
std Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-se 2022-12-28 22:22:18 +01:00
stdarch@790411f93c library: update stdarch submodule 2022-10-13 09:41:16 +08:00
test Fix uninlined_format_args in libtest 2022-12-19 08:58:40 +01:00
unwind Rollup merge of #104464 - mati865:reduce-eh-overallocation-amd64, r=thomcc 2022-11-22 16:36:37 +05:30