diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-12-19 10:29:23 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2019-01-07 08:00:47 -0800 |
| commit | 255a3f3e183150e30d411628d5996bd3a183bd6f (patch) | |
| tree | 8ad92dbbf5cd558da93028d0c38ed5810053f853 /src/libstd/sys/cloudabi | |
| parent | 1f7c44cdb2958ceb0a5d78634a704a492a241b6f (diff) | |
| download | rust-255a3f3e183150e30d411628d5996bd3a183bd6f.tar.gz rust-255a3f3e183150e30d411628d5996bd3a183bd6f.zip | |
std: Force `Instant::now()` to be monotonic
This commit is an attempt to force `Instant::now` to be monotonic through any means possible. We tried relying on OS/hardware/clock implementations, but those seem buggy enough that we can't rely on them in practice. This commit implements the same hammer Firefox recently implemented (noted in #56612) which is to just keep whatever the lastest `Instant::now()` return value was in memory, returning that instead of the OS looks like it's moving backwards. Closes #48514 Closes #49281 cc #51648 cc #56560 Closes #56612 Closes #56940
Diffstat (limited to 'src/libstd/sys/cloudabi')
| -rw-r--r-- | src/libstd/sys/cloudabi/time.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/sys/cloudabi/time.rs b/src/libstd/sys/cloudabi/time.rs index 906beba4ae1..545e3c0ce84 100644 --- a/src/libstd/sys/cloudabi/time.rs +++ b/src/libstd/sys/cloudabi/time.rs @@ -25,6 +25,14 @@ impl Instant { } } + pub fn actually_monotonic() -> bool { + true + } + + pub const fn zero() -> Instant { + Instant { t: 0 } + } + pub fn sub_instant(&self, other: &Instant) -> Duration { let diff = self.t .checked_sub(other.t) |
