]> git.proxmox.com Git - rustc.git/blobdiff - src/libstd/sys_common/thread_info.rs
New upstream version 1.20.0+dfsg1
[rustc.git] / src / libstd / sys_common / thread_info.rs
index 5ed48ee45587190e42a047427d4b3015ac012908..2abb8afa82848a5a8db1cddbc8c4c61589b06ba9 100644 (file)
@@ -12,7 +12,6 @@
 
 use cell::RefCell;
 use thread::Thread;
-use thread::LocalKeyState;
 
 struct ThreadInfo {
     stack_guard: Option<usize>,
@@ -23,19 +22,15 @@ thread_local! { static THREAD_INFO: RefCell<Option<ThreadInfo>> = RefCell::new(N
 
 impl ThreadInfo {
     fn with<R, F>(f: F) -> Option<R> where F: FnOnce(&mut ThreadInfo) -> R {
-        if THREAD_INFO.state() == LocalKeyState::Destroyed {
-            return None
-        }
-
-        THREAD_INFO.with(move |c| {
+        THREAD_INFO.try_with(move |c| {
             if c.borrow().is_none() {
                 *c.borrow_mut() = Some(ThreadInfo {
                     stack_guard: None,
                     thread: Thread::new(None),
                 })
             }
-            Some(f(c.borrow_mut().as_mut().unwrap()))
-        })
+            f(c.borrow_mut().as_mut().unwrap())
+        }).ok()
     }
 }