Debian Codegraph @

debian/rust-vendor/ctrlc/tests/main/test_signal_hook.rs

raw
1 // Copyright (c) 2023 CtrlC developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9
10 use std::sync::{
11 atomic::{AtomicBool, Ordering},
12 Arc,
13 };
14
15 pub fn run_signal_hook() {
16 let hook = Arc::new(AtomicBool::new(false));
17
18 signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&hook)).unwrap();
19
20 unsafe {
21 super::platform::raise_ctrl_c();
22 }
23
24 std::thread::sleep(std::time::Duration::from_millis(100));
25 assert!(hook.load(Ordering::SeqCst));
26 }