Files
rust/library/std/src
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
..
2022-08-01 20:10:40 +00:00
2022-11-17 12:50:33 -08:00
2022-11-17 12:50:33 -08:00
2022-11-14 14:25:44 +01:00
2022-11-13 18:49:21 +00:00
2022-08-18 18:07:39 -04:00
2022-12-05 16:42:36 +08:00
2022-09-26 10:14:45 +02:00
2022-11-17 12:50:33 -08:00
2022-11-17 12:50:33 -08:00
2022-10-07 15:21:47 +02:00
2022-12-16 16:52:36 -05:00
2022-11-06 17:11:02 -05:00