-
Notifications
You must be signed in to change notification settings - Fork 13k
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
thread_local: be excruciatingly explicit in dtor code #124387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use super::lazy::LazyKeyInner; | ||
use crate::cell::Cell; | ||
use crate::sys::thread_local_dtor::register_dtor; | ||
use crate::{fmt, mem, panic}; | ||
use crate::{fmt, mem, panic, ptr}; | ||
|
||
#[doc(hidden)] | ||
#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] | ||
|
@@ -237,8 +237,9 @@ unsafe extern "C" fn destroy_value<T>(ptr: *mut u8) { | |
// Wrap the call in a catch to ensure unwinding is caught in the event | ||
// a panic takes place in a destructor. | ||
if let Err(_) = panic::catch_unwind(panic::AssertUnwindSafe(|| unsafe { | ||
let value = (*ptr).inner.take(); | ||
(*ptr).dtor_state.set(DtorState::RunningOrHasRun); | ||
let Key { inner, dtor_state } = &*ptr; | ||
let value = inner.take(); | ||
dtor_state.set(DtorState::RunningOrHasRun); | ||
drop(value); | ||
Comment on lines
+241
to
243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something that's not clear to me is whether we can simply rearrange this: do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, and there are some other improvements possible as well, see #116123. |
||
})) { | ||
rtabort!("thread local panicked on drop"); | ||
|
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.
The purpose of adding this two-step is to make it clear, combined with the other change, that we are using internal mutability and not relying on upgrading the pointer to
&mut
.