From 5a2cbe708834e08c7f2d5935e04c7e0410bb0139 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 27 Dec 2017 04:25:46 +0000 Subject: [PATCH] runtime: remove borrow_mut!() in favor of backtraces. --- artiq/firmware/runtime/lib.rs | 11 +---------- artiq/firmware/runtime/sched.rs | 23 ++++++++++++----------- artiq/firmware/runtime/session.rs | 6 +++--- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index a8991557e..c30c6c8d5 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -26,15 +26,6 @@ use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr}; use proto::{mgmt_proto, analyzer_proto, moninj_proto, rpc_proto, session_proto, kernel_proto}; use amp::{mailbox, rpc_queue}; -macro_rules! borrow_mut { - ($x:expr) => ({ - match $x.try_borrow_mut() { - Ok(x) => x, - Err(_) => panic!("cannot borrow mutably at {}:{}", file!(), line!()) - } - }) -} - mod config; #[cfg(has_ethmac)] mod ethmac; @@ -194,7 +185,7 @@ fn startup_ethernet() { scheduler.run(); { - let sockets = &mut *borrow_mut!(scheduler.sockets()); + let sockets = &mut *scheduler.sockets().borrow_mut(); loop { match interface.poll(sockets, board::clock::get_ms()) { Ok(true) => (), diff --git a/artiq/firmware/runtime/sched.rs b/artiq/firmware/runtime/sched.rs index 1a6ce55b4..82738e9c4 100644 --- a/artiq/firmware/runtime/sched.rs +++ b/artiq/firmware/runtime/sched.rs @@ -124,7 +124,7 @@ impl Scheduler { pub fn run(&mut self) { self.sockets.borrow_mut().prune(); - self.threads.append(&mut *borrow_mut!(self.spawned)); + self.threads.append(&mut *self.spawned.borrow_mut()); if self.threads.len() == 0 { return } let now = board::clock::get_ms(); @@ -133,7 +133,7 @@ impl Scheduler { self.run_idx = (self.run_idx + 1) % self.threads.len(); let result = { - let mut thread = borrow_mut!(self.threads[self.run_idx].0); + let mut thread = self.threads[self.run_idx].0.borrow_mut(); match thread.waiting_for { _ if thread.interrupted => { thread.interrupted = false; @@ -164,7 +164,7 @@ impl Scheduler { }, Some(wait_request) => { // The thread has suspended itself. - let mut thread = borrow_mut!(self.threads[self.run_idx].0); + let mut thread = self.threads[self.run_idx].0.borrow_mut(); thread.waiting_for = wait_request } } @@ -189,7 +189,7 @@ impl<'a> Io<'a> { pub fn spawn(&self, stack_size: usize, f: F) -> ThreadHandle where F: 'static + FnOnce(Io) + Send { let handle = unsafe { Thread::new(self, stack_size, f) }; - borrow_mut!(self.spawned).push(handle.clone()); + self.spawned.borrow_mut().push(handle.clone()); handle } @@ -241,7 +241,7 @@ macro_rules! until { ($socket:expr, $ty:ty, |$var:ident| $cond:expr) => ({ let (sockets, handle) = ($socket.io.sockets.clone(), $socket.handle); $socket.io.until(move || { - let mut sockets = borrow_mut!(sockets); + let mut sockets = sockets.borrow_mut(); let $var = sockets.get::<$ty>(handle); $cond }) @@ -269,7 +269,8 @@ impl<'a> TcpListener<'a> { fn new_lower(io: &'a Io<'a>, buffer_size: usize) -> SocketHandle { let rx_buffer = vec![0; buffer_size]; let tx_buffer = vec![0; buffer_size]; - borrow_mut!(io.sockets) + io.sockets + .borrow_mut() .add(TcpSocketLower::new( TcpSocketBuffer::new(rx_buffer), TcpSocketBuffer::new(tx_buffer))) @@ -286,7 +287,7 @@ impl<'a> TcpListener<'a> { fn with_lower(&self, f: F) -> R where F: FnOnce(SocketRef) -> R { - let mut sockets = borrow_mut!(self.io.sockets); + let mut sockets = self.io.sockets.borrow_mut(); let result = f(sockets.get(self.handle.get())); result } @@ -327,7 +328,7 @@ impl<'a> TcpListener<'a> { // that still counts as accepting even though nothing may be sent. let (sockets, handle) = (self.io.sockets.clone(), self.handle.get()); self.io.until(move || { - let mut sockets = borrow_mut!(sockets); + let mut sockets = sockets.borrow_mut(); let socket = sockets.get::(handle); socket.may_send() || socket.may_recv() })?; @@ -352,7 +353,7 @@ impl<'a> TcpListener<'a> { impl<'a> Drop for TcpListener<'a> { fn drop(&mut self) { self.with_lower(|mut s| s.close()); - borrow_mut!(self.io.sockets).release(self.handle.get()) + self.io.sockets.borrow_mut().release(self.handle.get()) } } @@ -377,7 +378,7 @@ impl<'a> TcpStream<'a> { fn with_lower(&self, f: F) -> R where F: FnOnce(SocketRef) -> R { - let mut sockets = borrow_mut!(self.io.sockets); + let mut sockets = self.io.sockets.borrow_mut(); let result = f(sockets.get(self.handle)); result } @@ -496,6 +497,6 @@ impl<'a> Write for TcpStream<'a> { impl<'a> Drop for TcpStream<'a> { fn drop(&mut self) { self.with_lower(|mut s| s.close()); - borrow_mut!(self.io.sockets).release(self.handle) + self.io.sockets.borrow_mut().release(self.handle) } } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 263933765..349ba782f 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -634,7 +634,7 @@ pub fn thread(io: Io) { { let congress = congress.clone(); respawn(&io, &mut kernel_thread, move |io| { - let mut congress = borrow_mut!(congress); + let mut congress = congress.borrow_mut(); info!("running startup kernel"); match flash_kernel_worker(&io, &mut congress, "startup_kernel") { Ok(()) => info!("startup kernel finished"), @@ -669,7 +669,7 @@ pub fn thread(io: Io) { let congress = congress.clone(); let stream = stream.into_handle(); respawn(&io, &mut kernel_thread, move |io| { - let mut congress = borrow_mut!(congress); + let mut congress = congress.borrow_mut(); let mut stream = TcpStream::from_handle(&io, stream); match host_kernel_worker(&io, &mut stream, &mut *congress) { Ok(()) => (), @@ -692,7 +692,7 @@ pub fn thread(io: Io) { let congress = congress.clone(); respawn(&io, &mut kernel_thread, move |io| { - let mut congress = borrow_mut!(congress); + let mut congress = congress.borrow_mut(); match flash_kernel_worker(&io, &mut *congress, "idle_kernel") { Ok(()) => info!("idle kernel finished, standing by"),