about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-04 20:52:22 +0000
committerbors <bors@rust-lang.org>2016-02-04 20:52:22 +0000
commitc007e4a010e30db1c92bb3cd5157ffa8282dbbd6 (patch)
treec53645be61e98209da45e3ec52d923c269f5f8d4 /src/libstd
parentd0ef74026690cffccb543fc274d73a078eba797d (diff)
parent4b68c293fdf64749975adfa0c70c8b3eda649bad (diff)
downloadrust-c007e4a010e30db1c92bb3cd5157ffa8282dbbd6.tar.gz
rust-c007e4a010e30db1c92bb3cd5157ffa8282dbbd6.zip
Auto merge of #30759 - Manishearth:attr-tls, r=alexcrichton
fixes #30756

r? @Gankro
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/thread/local.rs50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index d1f5cf81c03..69395001bbf 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -92,7 +92,7 @@ pub struct LocalKey<T: 'static> {
     // trivially devirtualizable by LLVM because the value of `inner` never
     // changes and the constant should be readonly within a crate. This mainly
     // only runs into problems when TLS statics are exported across crates.
-    inner: unsafe fn() -> Option<&'static UnsafeCell<Option<T>>>,
+    inner: fn() -> Option<&'static UnsafeCell<Option<T>>>,
 
     // initialization routine to invoke to create a value
     init: fn() -> T,
@@ -126,7 +126,7 @@ macro_rules! __thread_local_inner {
     ($t:ty, $init:expr) => {{
         fn __init() -> $t { $init }
 
-        unsafe fn __getit() -> $crate::option::Option<
+        fn __getit() -> $crate::option::Option<
             &'static $crate::cell::UnsafeCell<
                 $crate::option::Option<$t>>>
         {
@@ -183,7 +183,7 @@ impl<T: 'static> LocalKey<T> {
     #[unstable(feature = "thread_local_internals",
                reason = "recently added to create a key",
                issue = "0")]
-    pub const fn new(inner: unsafe fn() -> Option<&'static UnsafeCell<Option<T>>>,
+    pub const fn new(inner: fn() -> Option<&'static UnsafeCell<Option<T>>>,
                      init: fn() -> T) -> LocalKey<T> {
         LocalKey {
             inner: inner,
@@ -303,11 +303,13 @@ pub mod elf {
             }
         }
 
-        pub unsafe fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
-            if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
-                return None
+        pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
+            unsafe {
+                if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
+                    return None
+                }
+                self.register_dtor();
             }
-            self.register_dtor();
             Some(&self.inner)
         }
 
@@ -452,24 +454,26 @@ pub mod os {
             }
         }
 
-        pub unsafe fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
-            let ptr = self.os.get() as *mut Value<T>;
-            if !ptr.is_null() {
-                if ptr as usize == 1 {
-                    return None
+        pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
+            unsafe {
+                let ptr = self.os.get() as *mut Value<T>;
+                if !ptr.is_null() {
+                    if ptr as usize == 1 {
+                        return None
+                    }
+                    return Some(&(*ptr).value);
                 }
-                return Some(&(*ptr).value);
-            }
 
-            // If the lookup returned null, we haven't initialized our own local
-            // copy, so do that now.
-            let ptr: Box<Value<T>> = box Value {
-                key: self,
-                value: UnsafeCell::new(None),
-            };
-            let ptr = Box::into_raw(ptr);
-            self.os.set(ptr as *mut u8);
-            Some(&(*ptr).value)
+                // If the lookup returned null, we haven't initialized our own local
+                // copy, so do that now.
+                let ptr: Box<Value<T>> = box Value {
+                    key: self,
+                    value: UnsafeCell::new(None),
+                };
+                let ptr = Box::into_raw(ptr);
+                self.os.set(ptr as *mut u8);
+                Some(&(*ptr).value)
+            }
         }
     }