1use std::sync::atomic::{AtomicBool, Ordering};
2
3static GLOBAL_EXIT: AtomicBool = AtomicBool::new(false);
4
5pub fn request_exit() {
7 GLOBAL_EXIT.store(true, Ordering::Release);
8}
9
10pub fn should_exit() -> bool {
12 GLOBAL_EXIT.load(Ordering::Acquire)
13}
14
15pub fn reset_exit() {
17 GLOBAL_EXIT.store(false, Ordering::Release);
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 #[test]
25 fn test_exit_flag() {
26 assert!(!should_exit());
27 request_exit();
28 assert!(should_exit());
29 reset_exit();
30 assert!(!should_exit());
31 }
32}