aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/sys_common
diff options
context:
space:
mode:
authorRonald Kinard <[email protected]>2017-07-26 14:30:16 -0500
committerGitHub <[email protected]>2017-07-26 14:30:16 -0500
commite4269846722d55f468b70ec721a087367ac66ed3 (patch)
treee927e578e35bb6ee04e9b8bb3fdd41c6c201494d /ctr-std/src/sys_common
parentMerge pull request #38 from FenrirWolf/examples (diff)
parentPrint thread name in panic msg (diff)
downloadctru-rs-e4269846722d55f468b70ec721a087367ac66ed3.tar.xz
ctru-rs-e4269846722d55f468b70ec721a087367ac66ed3.zip
Merge pull request #40 from FenrirWolf/thread-fix
Update thread module
Diffstat (limited to 'ctr-std/src/sys_common')
-rw-r--r--ctr-std/src/sys_common/thread_info.rs18
1 files changed, 4 insertions, 14 deletions
diff --git a/ctr-std/src/sys_common/thread_info.rs b/ctr-std/src/sys_common/thread_info.rs
index 95d8b6c..2abb8af 100644
--- a/ctr-std/src/sys_common/thread_info.rs
+++ b/ctr-std/src/sys_common/thread_info.rs
@@ -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: NewThread::new(None),
+ thread: Thread::new(None),
})
}
- Some(f(c.borrow_mut().as_mut().unwrap()))
- })
+ f(c.borrow_mut().as_mut().unwrap())
+ }).ok()
}
}
@@ -54,8 +49,3 @@ pub fn set(stack_guard: Option<usize>, thread: Thread) {
thread: thread,
}));
}
-
-// a hack to get around privacy restrictions; implemented by `std::thread`
-pub trait NewThread {
- fn new(name: Option<String>) -> Self;
-}