Skip to content

Commit 58220d7

Browse files
committed
Revert unnecessary changes
1 parent cc68e0e commit 58220d7

File tree

1 file changed

+5
-26
lines changed
  • library/std/src/sys/thread_local/key

1 file changed

+5
-26
lines changed

library/std/src/sys/thread_local/key/racy.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ impl LazyKey {
3535
}
3636

3737
#[inline]
38-
pub fn force(&'static self) -> super::Key {
38+
pub fn force(&self) -> super::Key {
3939
match self.key.load(Ordering::Acquire) {
4040
KEY_SENTVAL => self.lazy_init() as super::Key,
4141
n => n as super::Key,
4242
}
4343
}
4444

45-
fn lazy_init(&'static self) -> usize {
45+
fn lazy_init(&self) -> usize {
4646
// POSIX allows the key created here to be KEY_SENTVAL, but the compare_exchange
4747
// below relies on using KEY_SENTVAL as a sentinel value to check who won the
4848
// race to set the shared TLS key. As far as I know, there is no
@@ -63,7 +63,6 @@ impl LazyKey {
6363
key2
6464
};
6565
rtassert!(key as usize != KEY_SENTVAL);
66-
6766
match self.key.compare_exchange(
6867
KEY_SENTVAL,
6968
key as usize,
@@ -96,34 +95,14 @@ impl LazyKey {
9695
/// Thus we keep our own thread-local list for that purpose.
9796
#[cfg(not(target_thread_local))]
9897
fn lazy_keys() -> &'static crate::cell::RefCell<Vec<&'static LazyKey>> {
99-
static KEY: atomic::AtomicUsize = atomic::AtomicUsize::new(KEY_SENTVAL);
98+
static KEY: LazyKey = LazyKey::new(Some(drop_lazy_keys));
10099

101100
unsafe extern "C" fn drop_lazy_keys(ptr: *mut u8) {
102101
let ptr = ptr as *mut crate::cell::RefCell<Vec<&'static LazyKey>>;
103-
if !ptr.is_null() {
104-
drop(unsafe { Box::from_raw(ptr) });
105-
}
106-
}
107-
108-
// Allocate a TLS key to store the thread local destructor list.
109-
let mut key = KEY.load(Ordering::Acquire) as super::Key;
110-
if key == KEY_SENTVAL as _ {
111-
let new_key = super::create(Some(drop_lazy_keys));
112-
match KEY.compare_exchange_weak(
113-
KEY_SENTVAL,
114-
new_key as _,
115-
Ordering::Release,
116-
Ordering::Acquire,
117-
) {
118-
Ok(_) => key = new_key,
119-
Err(other_key) => {
120-
unsafe { super::destroy(new_key) };
121-
key = other_key as _;
122-
}
123-
}
102+
drop(unsafe { Box::from_raw(ptr) });
124103
}
125104

126-
// And allocate the list for this thread if necessary.
105+
let key = KEY.force();
127106
let mut ptr = unsafe { super::get(key) as *const crate::cell::RefCell<Vec<&'static LazyKey>> };
128107
if ptr.is_null() {
129108
let list = Box::new(crate::cell::RefCell::new(Vec::new()));

0 commit comments

Comments
 (0)