From 0cd87af386d11cbfb59c9e5a95566c7e809c96ce Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 4 Oct 2016 05:27:54 +0000 Subject: [PATCH] Rust: don't crash kernel CPU when no flash kernel is present. --- artiq/runtime.rs/src/sched.rs | 14 +++++++------- artiq/runtime.rs/src/session.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/artiq/runtime.rs/src/sched.rs b/artiq/runtime.rs/src/sched.rs index 87d8562ff..34dd5bc8c 100644 --- a/artiq/runtime.rs/src/sched.rs +++ b/artiq/runtime.rs/src/sched.rs @@ -214,13 +214,6 @@ unsafe impl Send for WaitEvent {} pub struct Waiter<'a>(&'a Yielder); impl<'a> Waiter<'a> { - pub fn relinquish(&self) { - self.0.suspend(WaitRequest { - timeout: None, - event: None - }); - } - pub fn sleep(&self, duration: Duration) -> Result<()> { let request = WaitRequest { timeout: Some(Instant::now() + duration), @@ -242,6 +235,13 @@ impl<'a> Waiter<'a> { } } + pub fn relinquish(&self) -> Result<()> { + self.suspend(WaitRequest { + timeout: None, + event: None + }) + } + pub fn join(&self, thread: ThreadHandle) -> Result<()> { self.suspend(WaitRequest { timeout: None, diff --git a/artiq/runtime.rs/src/session.rs b/artiq/runtime.rs/src/session.rs index 2188bd29b..ad3f9ee94 100644 --- a/artiq/runtime.rs/src/session.rs +++ b/artiq/runtime.rs/src/session.rs @@ -320,7 +320,7 @@ fn host_kernel_worker(waiter: Waiter, } } - waiter.relinquish() + try!(waiter.relinquish()) } } @@ -330,6 +330,13 @@ fn flash_kernel_worker(waiter: Waiter, let mut session = Session::new(congress); let kernel = config::read_to_end(config_key); + if kernel.len() == 0 { + info!("no kernel present in config key {}", config_key); + loop { + try!(waiter.relinquish()) + } + } + try!(unsafe { kern_load(waiter, &mut session, &kernel) }); try!(kern_run(&mut session)); @@ -410,6 +417,6 @@ pub fn handler(waiter: Waiter, spawner: Spawner) { }) } - waiter.relinquish() + let _ = waiter.relinquish(); } }