about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
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());
     }
 }