From b65b432762ad9d7953d2a1e130e0f1388d9b1711 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Fri, 19 Jun 2020 11:22:56 +0200 Subject: [PATCH] control flow cleanup --- tools/dk-run/src/main.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tools/dk-run/src/main.rs b/tools/dk-run/src/main.rs index 50ec002..63da642 100644 --- a/tools/dk-run/src/main.rs +++ b/tools/dk-run/src/main.rs @@ -192,29 +192,30 @@ fn notmain() -> Result { // run let core = Rc::new(core); - let mut num_retries = 5; - + let rtt_addr_result = rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?; let mut rtt: Result; + let mut num_retries = 3; // picked at random, increase if necessary loop { rtt = Rtt::attach_region( core.clone(), &sess, - &ScanRegion::Exact(rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?), // todo only do this once? + &ScanRegion::Exact(rtt_addr_result), ); - // todo clean up control flow - if rtt.is_ok() { - log::info!("Successfully attached RTT"); - break; + match rtt { + Ok(_) => { break; } + Err(res) => { + num_retries -= 1; + if num_retries == 0 { + log::info!("Max number of retries exceeded. Giving up."); + return Err(anyhow!(res)); + } + log::info!("Attaching RTT failed. retrying"); + } } - - num_retries -= 1; - if num_retries == 0 { - break; - } - log::info!("Attaching RTT failed. retrying"); } + log::info!("Successfully attached RTT"); let channel = rtt .unwrap() // using ? instead wouldn't show the user any helpful error message