forked from neovide/neovide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunning_tracker.rs
43 lines (35 loc) · 1009 Bytes
/
running_tracker.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::sync::{
atomic::{AtomicBool, AtomicI32, Ordering},
Arc,
};
use log::info;
lazy_static! {
pub static ref RUNNING_TRACKER: RunningTracker = RunningTracker::new();
}
pub struct RunningTracker {
running: Arc<AtomicBool>,
exit_code: Arc<AtomicI32>,
}
impl RunningTracker {
fn new() -> Self {
Self {
running: Arc::new(AtomicBool::new(true)),
exit_code: Arc::new(AtomicI32::new(0)),
}
}
pub fn quit(&self, reason: &str) {
self.running.store(false, Ordering::Relaxed);
info!("Quit {}", reason);
}
pub fn quit_with_code(&self, code: i32, reason: &str) {
self.exit_code.store(code, Ordering::Relaxed);
self.running.store(false, Ordering::Relaxed);
info!("Quit with code {}: {}", code, reason);
}
pub fn is_running(&self) -> bool {
self.running.load(Ordering::Relaxed)
}
pub fn exit_code(&self) -> i32 {
self.exit_code.load(Ordering::Relaxed)
}
}