Proper ctrl+c handling in Windows (fix #508)

This commit is contained in:
Roey Darwish Dror
2020-08-26 22:30:19 +03:00
parent 4657160f80
commit 1317e51096
7 changed files with 53 additions and 35 deletions

22
src/ctrlc/interrupted.rs Normal file
View File

@@ -0,0 +1,22 @@
use lazy_static::lazy_static;
use std::sync::atomic::{AtomicBool, Ordering};
lazy_static! {
/// A global variable telling whether the application has been interrupted.
static ref INTERRUPTED: AtomicBool = AtomicBool::new(false);
}
/// Tells whether the program has been interrupted
pub fn interrupted() -> bool {
INTERRUPTED.load(Ordering::SeqCst)
}
/// Clears the interrupted flag
pub fn unset_interrupted() {
debug_assert!(INTERRUPTED.load(Ordering::SeqCst));
INTERRUPTED.store(false, Ordering::SeqCst)
}
pub fn set_interrupted() {
INTERRUPTED.store(true, Ordering::SeqCst)
}