Commit eea8cee
authored
Rollup merge of rust-lang#121596 - ChrisDenton:tls, r=joboet
Use volatile access instead of `#[used]` for `on_tls_callback`
The first commit adds a volatile load of `p_thread_callback` when registering a dtor so that the compiler knows if the callback is used or not. I don't believe the added volatile instruction is otherwise significant in the context. In my testing using the volatile load allowed the compiler to correctly reason about whether `on_tls_callback` is used or not, allowing it to be omitted entirely in some cases. Admittedly it usually is used due to `Thread` but that can be avoided (e.g. in DLLs or with custom entry points that avoid the offending APIs). Ideally this would be something the compiler could help a bit more with so we didn't have to use tricks like `#[used]` or volatile. But alas.
I also used this as an opportunity to clean up the `unused` lints which I don't think serve a purpose any more.
The second commit removes the volatile load of `_tls_used` with `#cfg[target_thread_local]` because `#[thread_local]` already implies it. And if it ever didn't then `#[thread_local]` would be broken when there aren't any dtors.1 file changed
+13
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
| |||
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| 23 | + | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | | - | |
32 | | - | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
| |||
130 | 125 | | |
131 | 126 | | |
132 | 127 | | |
| 128 | + | |
133 | 129 | | |
134 | 130 | | |
135 | 131 | | |
| |||
215 | 211 | | |
216 | 212 | | |
217 | 213 | | |
218 | | - | |
219 | 214 | | |
220 | 215 | | |
221 | 216 | | |
| |||
281 | 276 | | |
282 | 277 | | |
283 | 278 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | 279 | | |
288 | 280 | | |
289 | 281 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
295 | 289 | | |
296 | 290 | | |
297 | 291 | | |
| |||
301 | 295 | | |
302 | 296 | | |
303 | 297 | | |
304 | | - | |
305 | | - | |
306 | | - | |
| 298 | + | |
| 299 | + | |
307 | 300 | | |
308 | 301 | | |
309 | 302 | | |
310 | 303 | | |
311 | 304 | | |
312 | | - | |
313 | | - | |
314 | 305 | | |
315 | 306 | | |
316 | | - | |
| 307 | + | |
317 | 308 | | |
318 | 309 | | |
319 | 310 | | |
| |||
0 commit comments