From 7b9770b1e482dfc079022ff0b5a5e6eaa26a8542 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 11 May 2020 18:02:03 +0300 Subject: [PATCH] fix(cli): Don't grab write lock in threads until results ready --- src/status/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/status/mod.rs b/src/status/mod.rs index 678c6bb1..5ef726d2 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -18,27 +18,33 @@ pub fn run() -> Result<()> { /// Evaluate whether this project is pis_setup()?roperly configured pub fn is_setup() -> Result { let results = Arc::new(RwLock::new(Vec::new())); + // First round of tests, entirely independent rayon::scope(|s| { s.spawn(|_| { - results.write().unwrap().push(is_repo().unwrap()); + let ret = is_repo().unwrap(); + results.write().unwrap().push(ret); }); s.spawn(|_| { - results.write().unwrap().push(is_make_exectuable().unwrap()); + let ret = is_make_exectuable().unwrap(); + results.write().unwrap().push(ret); }); }); - let ret = results.read().unwrap().iter().all(|&v| v); + // Second round of tests, dependent on first set - if ret { + if results.read().unwrap().iter().all(|&v| v) { rayon::scope(|s| { s.spawn(|_| { - results.write().unwrap().push(is_writable().unwrap()); + let ret = is_writable().unwrap(); + results.write().unwrap().push(ret); }); s.spawn(|_| { - results.write().unwrap().push(is_make_gnu().unwrap()); + let ret = is_make_gnu().unwrap(); + results.write().unwrap().push(ret); }); }); } + let ret = results.read().unwrap().iter().all(|&v| v); let msg = LocalText::new(if ret { "status-good" } else { "status-bad" }).fmt(); eprintln!(