🐛 Stabilise: two starts of one range no longer both run
Browse files at this commit77c58ca168c93c901ee1562ff4f2b51a8a35288eParent: c002f131 changed file +6 -2
crates/engine/src/stabilise.rsmodified+6 -2
| @@ -988,9 +988,13 @@ pub fn start(source: &Path, lo: u32, hi: u32) -> Status { | |||
| 988 | return status(source, lo, hi); | 988 | return status(source, lo, hi); |
| 989 | }; | 989 | }; |
| 990 | let job = Arc::new(Job { progress: AtomicU32::new(0), cancel: AtomicBool::new(false), outcome: Mutex::new(None) }); | 990 | let job = Arc::new(Job { progress: AtomicU32::new(0), cancel: AtomicBool::new(false), outcome: Mutex::new(None) }); |
| 991 | - if let Ok(mut j) = jobs().lock() { | 991 | + // The check and the insert share one lock, so two starts cannot both see the range as missing. |
| 992 | - j.insert(key.clone(), job.clone()); | 992 | + let mut map = jobs().lock().unwrap_or_else(|e| e.into_inner()); |
| 993 | + if let Some(running) = map.get(&key).filter(|j| j.outcome.lock().unwrap_or_else(|e| e.into_inner()).is_none()) { | ||
| 994 | + return Status::Running(running.progress.load(Ordering::Relaxed) as f32 / 1000.0); | ||
| 993 | } | 995 | } |
| 996 | + map.insert(key.clone(), job.clone()); | ||
| 997 | + drop(map); | ||
| 994 | let source = source.to_path_buf(); | 998 | let source = source.to_path_buf(); |
| 995 | std::thread::spawn(move || { | 999 | std::thread::spawn(move || { |
| 996 | let measured = analyse(&source, lo, hi, &job.progress, &job.cancel); | 1000 | let measured = analyse(&source, lo, hi, &job.progress, &job.cancel); |