address review comments

This commit is contained in:
Christian Poveda 2022-09-12 16:32:09 -05:00
parent b16d301dd9
commit c834637626
No known key found for this signature in database
GPG Key ID: 27525EF5E7420A50
3 changed files with 7 additions and 11 deletions

View File

@ -1,13 +1,9 @@
use std::sync::atomic::AtomicU64; use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{Duration, Instant as StdInstant}; use std::time::{Duration, Instant as StdInstant};
use rustc_data_structures::sync::Ordering; /// When using a virtual clock, this defines how many nanoseconds we pretend are passing for each
/// basic block.
use crate::*; const NANOSECONDS_PER_BASIC_BLOCK: u64 = 10;
/// When using a virtual clock, this defines how many nanoseconds do we pretend
/// are passing for each basic block.
const NANOSECOND_PER_BASIC_BLOCK: u64 = 10;
#[derive(Debug)] #[derive(Debug)]
pub struct Instant { pub struct Instant {
@ -83,7 +79,7 @@ impl Clock {
// Time will pass without us doing anything. // Time will pass without us doing anything.
} }
ClockKind::Virtual { nanoseconds } => { ClockKind::Virtual { nanoseconds } => {
nanoseconds.fetch_add(NANOSECOND_PER_BASIC_BLOCK, Ordering::SeqCst); nanoseconds.fetch_add(NANOSECONDS_PER_BASIC_BLOCK, Ordering::SeqCst);
} }
} }
} }

View File

@ -38,7 +38,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
[this.eval_libc_i32("CLOCK_MONOTONIC")?, this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?]; [this.eval_libc_i32("CLOCK_MONOTONIC")?, this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?];
let duration = if absolute_clocks.contains(&clk_id) { let duration = if absolute_clocks.contains(&clk_id) {
this.check_no_isolation("`clock_gettime` with real time clocks")?; this.check_no_isolation("`clock_gettime` with `REALTIME` clocks")?;
system_time_to_duration(&SystemTime::now())? system_time_to_duration(&SystemTime::now())?
} else if relative_clocks.contains(&clk_id) { } else if relative_clocks.contains(&clk_id) {
this.machine.clock.now().duration_since(this.machine.clock.anchor()) this.machine.clock.now().duration_since(this.machine.clock.anchor())

View File

@ -8,7 +8,7 @@ fn test_sleep() {
assert!((after - before).as_secs() >= 3600); assert!((after - before).as_secs() >= 3600);
} }
/// Ensure that time passes even if we don't sleep (but just wor). /// Ensure that time passes even if we don't sleep (but just work).
fn test_time_passes() { fn test_time_passes() {
// Check `Instant`. // Check `Instant`.
let now1 = Instant::now(); let now1 = Instant::now();