Revert "ensure fast thread local lookups occur once per access on macos"

This reverts commit d252f3b77f3b7d4cd59620588f9d026633c05816.
This commit is contained in:
tyler 2019-04-30 18:24:38 -07:00
parent 430a091cd8
commit 7acfb99adc
4 changed files with 6 additions and 32 deletions

View file

@ -1,8 +1,4 @@
#![cfg(target_thread_local)]
#![unstable(feature = "thread_local_internals", issue = "0")]
pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor;
pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T {
*ptr
}
pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor;

View file

@ -82,20 +82,3 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
}
}
}
#[cfg(not(target_os = "macos"))]
pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T {
*ptr
}
#[cfg(target_os = "macos")]
pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T {
// On macos, thread_local lookups can result in terrible code due to
// aggressive rerunning of the macos equivalent of `__tls_get_addr` - four
// lookups per actual reference in user code.
//
// Using a read_volatile on a value holding fast Key's address tricks the
// optimizer into only calling the macos get_addr equivalent once per time
// requested by the user.
crate::ptr::read_volatile(ptr)
}

View file

@ -2,7 +2,3 @@
#![cfg(target_thread_local)]
pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor;
pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T {
*ptr
}

View file

@ -344,7 +344,7 @@ pub mod fast {
use crate::fmt;
use crate::mem;
use crate::ptr;
use crate::sys::fast_thread_local::{lookup_once, register_dtor};
use crate::sys::fast_thread_local::register_dtor;
pub struct Key<T> {
inner: UnsafeCell<Option<T>>,
@ -371,12 +371,11 @@ pub mod fast {
}
pub unsafe fn get(&self) -> Option<&'static UnsafeCell<Option<T>>> {
let this = lookup_once(&self);
if mem::needs_drop::<T>() && this.dtor_running.get() {
if mem::needs_drop::<T>() && self.dtor_running.get() {
return None
}
this.register_dtor();
Some(&*(&this.inner as *const _))
self.register_dtor();
Some(&*(&self.inner as *const _))
}
unsafe fn register_dtor(&self) {
@ -396,7 +395,7 @@ pub mod fast {
// destructor as running for this thread so calls to `get` will return
// `None`.
(*ptr).dtor_running.set(true);
ptr::drop_in_place((*ptr).inner.get());
}
}