From 398b709e25796709d740bd77720fd8d23a101ea8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 4 Oct 2016 03:26:53 +0000 Subject: [PATCH] Rust: use try_borrow where applicable. --- artiq/runtime.rs/src/lib.rs | 2 +- artiq/runtime.rs/src/sched.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/artiq/runtime.rs/src/lib.rs b/artiq/runtime.rs/src/lib.rs index 9b913c9dd..4ddb0ba52 100644 --- a/artiq/runtime.rs/src/lib.rs +++ b/artiq/runtime.rs/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(libc, borrow_state, const_fn)] +#![feature(libc, borrow_state, const_fn, try_borrow)] #[macro_use] extern crate std_artiq as std; diff --git a/artiq/runtime.rs/src/sched.rs b/artiq/runtime.rs/src/sched.rs index 124af9410..a5ab646ce 100644 --- a/artiq/runtime.rs/src/sched.rs +++ b/artiq/runtime.rs/src/sched.rs @@ -68,17 +68,16 @@ impl ThreadHandle { } pub fn terminated(&self) -> bool { - match self.0.borrow_state() { - BorrowState::Unused => self.0.borrow().terminated(), - _ => false // the running thread hasn't terminated + match self.0.try_borrow() { + Ok(thread) => thread.terminated(), + Err(_) => false // the running thread hasn't terminated } } pub fn interrupt(&self) { - // FIXME: use try_borrow() instead once it's available - match self.0.borrow_state() { - BorrowState::Unused => self.0.borrow_mut().interrupt(), - _ => panic!("cannot interrupt the running thread") + match self.0.try_borrow_mut() { + Ok(mut thread) => thread.interrupt(), + Err(_) => panic!("cannot interrupt the running thread") } } }