platform_millis_linux/
lib.rs

1pub use platform_millis::{ms, PlatformMillis};
2use std::sync::Mutex;
3use std::sync::Once;
4use std::time::Instant;
5
6lazy_static::lazy_static! {
7  static ref START: Mutex<Option<Instant>> = Mutex::new(None);
8  static ref INIT_ONCE: Once = Once::new();
9}
10
11pub struct LinuxMillis;
12
13impl PlatformMillis for LinuxMillis {
14    fn millis() -> ms {
15        INIT_ONCE.call_once(|| {
16            let mut start = START.lock().unwrap();
17            *start = Some(Instant::now());
18        });
19
20        let start = START.lock().unwrap();
21        match *start {
22            Some(instant) => {
23                let elapsed = Instant::now().duration_since(instant);
24                elapsed.as_millis() as ms
25            }
26            _ => 0, // Return 0 if start time is not initialized
27        }
28    }
29}