about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-04-30 22:30:50 +1200
committerNick Cameron <ncameron@mozilla.com>2015-04-30 22:30:50 +1200
commitb2ddd937b20d8fc26132cb7ec665784422d92926 (patch)
treecf257df60ded1b45616d797b8feb71178cab0142 /src/libstd/thread
parentc0a42aecbc85298fb6351253c4cd1824567b7a42 (diff)
parentf0bd14f7b15b978f8bf32bb368f63faa0f26c02e (diff)
downloadrust-b2ddd937b20d8fc26132cb7ec665784422d92926.tar.gz
rust-b2ddd937b20d8fc26132cb7ec665784422d92926.zip
Merge branch 'master' into mulit-decor
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/local.rs25
-rw-r--r--src/libstd/thread/mod.rs12
-rw-r--r--src/libstd/thread/scoped_tls.rs3
3 files changed, 12 insertions, 28 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index 6d8f1cba709..bb2832b8746 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -18,7 +18,6 @@ use cell::UnsafeCell;
 
 // Sure wish we had macro hygiene, no?
 #[doc(hidden)]
-#[unstable(feature = "thread_local_internals")]
 pub mod __impl {
     pub use super::imp::Key as KeyInner;
     pub use super::imp::destroy_value;
@@ -78,12 +77,10 @@ pub struct LocalKey<T> {
     // This is trivially devirtualizable by LLVM because we never store anything
     // to this field and rustc can declare the `static` as constant as well.
     #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub inner: fn() -> &'static __impl::KeyInner<UnsafeCell<Option<T>>>,
 
     // initialization routine to invoke to create a value
     #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub init: fn() -> T,
 }
 
@@ -297,6 +294,7 @@ impl<T: 'static> LocalKey<T> {
 }
 
 #[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))]
+#[doc(hidden)]
 mod imp {
     use prelude::v1::*;
 
@@ -304,8 +302,6 @@ mod imp {
     use intrinsics;
     use ptr;
 
-    #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub struct Key<T> {
         // Place the inner bits in an `UnsafeCell` to currently get around the
         // "only Sync statics" restriction. This allows any type to be placed in
@@ -313,20 +309,16 @@ mod imp {
         //
         // Note that all access requires `T: 'static` so it can't be a type with
         // any borrowed pointers still.
-        #[unstable(feature = "thread_local_internals")]
         pub inner: UnsafeCell<T>,
 
         // Metadata to keep track of the state of the destructor. Remember that
         // these variables are thread-local, not global.
-        #[unstable(feature = "thread_local_internals")]
         pub dtor_registered: UnsafeCell<bool>, // should be Cell
-        #[unstable(feature = "thread_local_internals")]
         pub dtor_running: UnsafeCell<bool>, // should be Cell
     }
 
     unsafe impl<T> ::marker::Sync for Key<T> { }
 
-    #[doc(hidden)]
     impl<T> Key<T> {
         pub unsafe fn get(&'static self) -> Option<&'static T> {
             if intrinsics::needs_drop::<T>() && *self.dtor_running.get() {
@@ -364,6 +356,7 @@ mod imp {
         use sys_common::thread_local as os;
 
         extern {
+            #[linkage = "extern_weak"]
             static __dso_handle: *mut u8;
             #[linkage = "extern_weak"]
             static __cxa_thread_atexit_impl: *const ();
@@ -422,8 +415,6 @@ mod imp {
         _tlv_atexit(dtor, t);
     }
 
-    #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub unsafe extern fn destroy_value<T>(ptr: *mut u8) {
         let ptr = ptr as *mut Key<T>;
         // Right before we run the user destructor be sure to flag the
@@ -435,6 +426,7 @@ mod imp {
 }
 
 #[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))]
+#[doc(hidden)]
 mod imp {
     use prelude::v1::*;
 
@@ -444,16 +436,12 @@ mod imp {
     use ptr;
     use sys_common::thread_local::StaticKey as OsStaticKey;
 
-    #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub struct Key<T> {
         // Statically allocated initialization expression, using an `UnsafeCell`
         // for the same reasons as above.
-        #[unstable(feature = "thread_local_internals")]
         pub inner: UnsafeCell<T>,
 
         // OS-TLS key that we'll use to key off.
-        #[unstable(feature = "thread_local_internals")]
         pub os: OsStaticKey,
     }
 
@@ -464,7 +452,6 @@ mod imp {
         value: T,
     }
 
-    #[doc(hidden)]
     impl<T> Key<T> {
         pub unsafe fn get(&'static self) -> Option<&'static T> {
             self.ptr().map(|p| &*p)
@@ -489,14 +476,12 @@ mod imp {
                 key: self,
                 value: mem::transmute_copy(&self.inner),
             };
-            let ptr: *mut Value<T> = boxed::into_raw(ptr);
+            let ptr = boxed::into_raw(ptr);
             self.os.set(ptr as *mut u8);
             Some(&mut (*ptr).value as *mut T)
         }
     }
 
-    #[doc(hidden)]
-    #[unstable(feature = "thread_local_internals")]
     pub unsafe extern fn destroy_value<T: 'static>(ptr: *mut u8) {
         // The OS TLS ensures that this key contains a NULL value when this
         // destructor starts to run. We set it back to a sentinel value of 1 to
@@ -505,7 +490,7 @@ mod imp {
         //
         // Note that to prevent an infinite loop we reset it back to null right
         // before we return from the destructor ourselves.
-        let ptr: Box<Value<T>> = Box::from_raw(ptr as *mut Value<T>);
+        let ptr = Box::from_raw(ptr as *mut Value<T>);
         let key = ptr.key;
         key.os.set(1 as *mut u8);
         drop(ptr);
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 28e4650478b..bcc70c2b816 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -115,8 +115,7 @@
 //! ## Configuring threads
 //!
 //! A new thread can be configured before it is spawned via the `Builder` type,
-//! which currently allows you to set the name, stack size, and writers for
-//! `println!` and `panic!` for the child thread:
+//! which currently allows you to set the name and stack size for the child thread:
 //!
 //! ```rust
 //! # #![allow(unused_must_use)]
@@ -264,7 +263,7 @@ impl Builder {
     ///
     /// The child thread may outlive the parent (unless the parent thread
     /// is the main thread; the whole process is terminated when the main
-    /// thread finishes.) The join handle can be used to block on
+    /// thread finishes). The join handle can be used to block on
     /// termination of the child thread, including recovering its panics.
     ///
     /// # Errors
@@ -408,7 +407,9 @@ pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where
 /// Gets a handle to the thread that invokes it.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn current() -> Thread {
-    thread_info::current_thread()
+    thread_info::current_thread().expect("use of std::thread::current() is not \
+                                          possible after the thread's local \
+                                          data has been destroyed")
 }
 
 /// Cooperatively gives up a timeslice to the OS scheduler.
@@ -699,7 +700,6 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> {
     }
 }
 
-#[unsafe_destructor]
 #[unstable(feature = "scoped",
            reason = "memory unsafe if destructor is avoided, see #24292")]
 impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> {
@@ -722,7 +722,7 @@ fn _assert_sync_and_send() {
 ////////////////////////////////////////////////////////////////////////////////
 
 #[cfg(test)]
-mod test {
+mod tests {
     use prelude::v1::*;
 
     use any::Any;
diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs
index 9c0b4a5d833..35684a1f390 100644
--- a/src/libstd/thread/scoped_tls.rs
+++ b/src/libstd/thread/scoped_tls.rs
@@ -171,8 +171,7 @@ impl<T> ScopedKey<T> {
             key: &'a __impl::KeyInner<T>,
             val: *mut T,
         }
-        #[unsafe_destructor]
-        impl<'a, T> Drop for Reset<'a, T> {
+                impl<'a, T> Drop for Reset<'a, T> {
             fn drop(&mut self) {
                 unsafe { self.key.set(self.val) }
             }