7
7
// notice may not be copied, modified, or distributed except
8
8
// according to those terms.
9
9
10
- //! Cross platform handling of Ctrl-C signals.
11
- //!
12
- //! [HandlerRoutine]:https://msdn.microsoft.com/en-us/library/windows/desktop/ms683242.aspx
13
- //!
14
- //! [set_handler()](fn.set_handler.html) allows setting a handler closure which is executed on
15
- //! `Ctrl+C`. On Unix, this corresponds to a `SIGINT` signal. On windows, `Ctrl+C` corresponds to
16
- //! [`CTRL_C_EVENT`][HandlerRoutine] or [`CTRL_BREAK_EVENT`][HandlerRoutine].
17
- //!
18
- //! Setting a handler will start a new dedicated signal handling thread where we
19
- //! execute the handler each time we receive a `Ctrl+C` signal. There can only be
20
- //! one handler, you would typically set one at the start of your program.
21
- //!
22
- //! This package was further modified for stacks-blockchain to handle SIGBUS in order to gracefully
23
- //! shut down the node in the event of a sqlite memory error.
24
- //!
25
- //! # Example
26
- //! ```no_run
27
- //! use std::sync::atomic::{AtomicBool, Ordering};
28
- //! use std::sync::Arc;
29
- //!
30
- //! fn main() {
31
- //! let running = Arc::new(AtomicBool::new(true));
32
- //! let r = running.clone();
33
- //!
34
- //! ctrlc::set_handler(move || {
35
- //! r.store(false, Ordering::SeqCst);
36
- //! }).expect("Error setting Ctrl-C handler");
37
- //!
38
- //! println!("Waiting for Ctrl-C...");
39
- //! while running.load(Ordering::SeqCst) {}
40
- //! println!("Got it! Exiting...");
41
- //! }
42
- //! ```
43
- //!
44
-
45
10
#[ macro_use]
46
11
47
12
mod error;
@@ -50,6 +15,9 @@ pub use self::error::Error;
50
15
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
51
16
use std:: thread;
52
17
18
+ #[ cfg( test) ]
19
+ mod tests;
20
+
53
21
#[ derive( PartialEq , Clone ) ]
54
22
#[ repr( u8 ) ]
55
23
pub enum SignalId {
0 commit comments