X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibstd%2Fsys_common%2Fthread_info.rs;h=f09d16c33e6d6401470b61814af5e2ea39ff27b8;hb=4436c9d35498e7ae3da261f6141d6d73b915e1e8;hp=d75cbded7347b2936d03b0ac571b93e2902d63e2;hpb=f305b025cf907d0bbdd2135ec59d89cd32e5cbe9;p=rust.git diff --git a/src/libstd/sys_common/thread_info.rs b/src/libstd/sys_common/thread_info.rs index d75cbded734..f09d16c33e6 100644 --- a/src/libstd/sys_common/thread_info.rs +++ b/src/libstd/sys_common/thread_info.rs @@ -1,18 +1,8 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - #![allow(dead_code)] // stack_guard isn't used right now on all platforms -use cell::RefCell; -use sys::thread::guard::Guard; -use thread::Thread; +use crate::cell::RefCell; +use crate::sys::thread::guard::Guard; +use crate::thread::Thread; struct ThreadInfo { stack_guard: Option, @@ -22,16 +12,19 @@ struct ThreadInfo { thread_local! { static THREAD_INFO: RefCell> = RefCell::new(None) } impl ThreadInfo { - fn with(f: F) -> Option where F: FnOnce(&mut ThreadInfo) -> R { - THREAD_INFO.try_with(move |c| { - if c.borrow().is_none() { - *c.borrow_mut() = Some(ThreadInfo { - stack_guard: None, - thread: Thread::new(None), - }) - } - f(c.borrow_mut().as_mut().unwrap()) - }).ok() + fn with(f: F) -> Option + where + F: FnOnce(&mut ThreadInfo) -> R, + { + THREAD_INFO + .try_with(move |c| { + if c.borrow().is_none() { + *c.borrow_mut() = + Some(ThreadInfo { stack_guard: None, thread: Thread::new(None) }) + } + f(c.borrow_mut().as_mut().unwrap()) + }) + .ok() } } @@ -45,10 +38,7 @@ pub fn stack_guard() -> Option { pub fn set(stack_guard: Option, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); - THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ - stack_guard, - thread, - })); + THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo { stack_guard, thread })); } pub fn reset_guard(stack_guard: Option) {