-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor improvements to Windows TLS dtors #113907
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me.
Ordering::{AcqRel, Acquire, Relaxed, Release}, | ||
}; | ||
use crate::sys::c; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
/// An optimization hint. The compiler is often smart enough to know if an atomic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised the compiler can do this! That's an improvement -- it definitely didn't used to be able to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye. In my tests it seems to work well for simple local-ish cases. Dunno if it'd hold up in more complex cases tho.
@bors r+ |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#113380 (style-guide: clean up "must"/"should"/"may") - rust-lang#113723 (Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.) - rust-lang#113780 (Support `--print KIND=PATH` command line syntax) - rust-lang#113810 (Make {Rc,Arc}::allocator associated functions) - rust-lang#113907 (Minor improvements to Windows TLS dtors) Failed merges: - rust-lang#113392 (style-guide: Some cleanups from the fmt-rfcs repo history) r? `@ghost` `@rustbot` modify labels: rollup
IIRC, there is always at least one destructor (for threads spawned by |
Well it worked in practice for a lib I built. Admittedly I was using build-std. |
Huh. That's cool, nevermind then! |
Well you're absolutely right about an exe. Or anything else that touches ThreadInfo. I did briefly look at making it so ThreadInfo didn't require dropping but I don't think it's possible atm. At the very least it requires a recent version of Windows to be able to get the OS to store the thread name itself. |
This does a few things:
on_tls_callback
function because of dylib mess. We keep theinline(never)
hints as a precaution (see also the issue they link to).HAS_DTORS
atomic as an optimization hint. This allows removing (most) of the TLS dtor code if no dtors are ever run. Otherwise it's always included because of a#[used]
.assert
to make sure this is true.