about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authortyler <tyler@brainiumstudios.com>2019-04-27 08:01:32 -0700
committertyler <tyler@brainiumstudios.com>2019-05-15 07:30:33 -0700
commit430a091cd80c0e4b6bf44f6a19463a832e566f97 (patch)
tree9c9d3baeed0c0eab8d434a76b41148997d42611a /src/libstd/thread
parentae4be16e407061828fe604b1ccbd61181b14a3f1 (diff)
downloadrust-430a091cd80c0e4b6bf44f6a19463a832e566f97.tar.gz
rust-430a091cd80c0e4b6bf44f6a19463a832e566f97.zip
ensure fast thread local lookups occur once per access on macos
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/local.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index 0d5e1f2af38..9ce2fcf2352 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -344,7 +344,7 @@ pub mod fast {
     use crate::fmt;
     use crate::mem;
     use crate::ptr;
-    use crate::sys::fast_thread_local::register_dtor;
+    use crate::sys::fast_thread_local::{lookup_once, register_dtor};
 
     pub struct Key<T> {
         inner: UnsafeCell<Option<T>>,
@@ -371,11 +371,12 @@ pub mod fast {
         }
 
         pub unsafe fn get(&self) -> Option<&'static UnsafeCell<Option<T>>> {
-            if mem::needs_drop::<T>() && self.dtor_running.get() {
+            let this = lookup_once(&self);
+            if mem::needs_drop::<T>() && this.dtor_running.get() {
                 return None
             }
-            self.register_dtor();
-            Some(&*(&self.inner as *const _))
+            this.register_dtor();
+            Some(&*(&this.inner as *const _))
         }
 
         unsafe fn register_dtor(&self) {
@@ -395,7 +396,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());
     }
 }