Cancel generation when its handle is dropped

This commit is contained in:
Georg Bauer
2026-07-25 12:47:42 +02:00
parent d456458133
commit 218c9473f7

View File

@@ -3,7 +3,7 @@ use crate::metrics::{Metrics, WorkSource};
use crate::settings::{EngineSettings, TurnSettings};
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, Receiver, Sender};
use std::thread;
use std::time::{Duration, Instant};
@@ -19,6 +19,12 @@ pub(crate) struct ActiveGeneration {
pub(crate) cancel: Arc<AtomicBool>,
}
impl Drop for ActiveGeneration {
fn drop(&mut self) {
self.cancel.store(true, Ordering::Relaxed);
}
}
pub(crate) enum CheckpointTarget {
Local(PathBuf),
Transient(PathBuf),
@@ -218,3 +224,21 @@ fn run(commands: Receiver<Command>, metrics: Arc<Metrics>) {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dropping_active_generation_cancels_it() {
let cancel = Arc::new(AtomicBool::new(false));
let (_, events) = mpsc::channel();
drop(ActiveGeneration {
events,
cancel: Arc::clone(&cancel),
});
assert!(cancel.load(Ordering::Relaxed));
}
}