Proper ctrl+c handling in Windows (fix #508)
This commit is contained in:
@@ -1,27 +1,10 @@
|
||||
//! SIGINT handling in Unix systems.
|
||||
use lazy_static::lazy_static;
|
||||
use crate::ctrlc::interrupted::set_interrupted;
|
||||
use nix::sys::signal;
|
||||
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)
|
||||
}
|
||||
|
||||
/// Handle SIGINT. Set the interruption flag.
|
||||
extern "C" fn handle_sigint(_: i32) {
|
||||
INTERRUPTED.store(true, Ordering::SeqCst)
|
||||
set_interrupted()
|
||||
}
|
||||
|
||||
/// Set the necessary signal handlers.
|
||||
|
||||
Reference in New Issue
Block a user