1
Fork 0

where available use 64- or 128bit atomics instead of a Mutex to monotonize time

This commit is contained in:
The8472 2021-06-12 10:25:41 +02:00
parent ae90dcf020
commit 3914a7b0da
3 changed files with 122 additions and 12 deletions

View file

@ -12,15 +12,14 @@
#![stable(feature = "time", since = "1.3.0")]
mod monotonic;
#[cfg(test)]
mod tests;
use crate::cmp;
use crate::error::Error;
use crate::fmt;
use crate::ops::{Add, AddAssign, Sub, SubAssign};
use crate::sys::time;
use crate::sys_common::mutex::StaticMutex;
use crate::sys_common::FromInner;
#[stable(feature = "time", since = "1.3.0")]
@ -249,14 +248,7 @@ impl Instant {
return Instant(os_now);
}
static LOCK: StaticMutex = StaticMutex::new();
static mut LAST_NOW: time::Instant = time::Instant::zero();
unsafe {
let _lock = LOCK.lock();
let now = cmp::max(LAST_NOW, os_now);
LAST_NOW = now;
Instant(now)
}
Instant(monotonic::monotonize(os_now))
}
/// Returns the amount of time elapsed from another instant to this one.