Skip to content

Commit e93c719

Browse files
committed
rename checked_add methods
1 parent 9f39e3e commit e93c719

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/shims/time.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Clock {
6666
}
6767

6868
/// Compute `now + duration` relative to this clock.
69-
pub fn checked_add_since_now(&self, duration: Duration) -> Option<Time> {
69+
pub fn get_time_relative(&self, duration: Duration) -> Option<Time> {
7070
match self {
7171
Self::Host { .. } => Instant::now().checked_add(duration).map(Time::Monotonic),
7272
Self::Virtual { nanoseconds } =>
@@ -79,7 +79,7 @@ impl Clock {
7979

8080
/// Compute `start + duration` relative to this clock where `start` is the instant of time when
8181
/// this clock was created.
82-
pub fn checked_add_since_start(&self, duration: Duration) -> Option<Time> {
82+
pub fn get_time_absolute(&self, duration: Duration) -> Option<Time> {
8383
match self {
8484
Self::Host { time_anchor } => time_anchor.checked_add(duration).map(Time::Monotonic),
8585
Self::Virtual { .. } =>
@@ -301,10 +301,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
301301
}
302302
};
303303
// If adding the duration overflows, let's just sleep for an hour. Waking up early is always acceptable.
304-
let timeout_time =
305-
this.machine.clock.checked_add_since_now(duration).unwrap_or_else(|| {
306-
this.machine.clock.checked_add_since_now(Duration::from_secs(3600)).unwrap()
307-
});
304+
let timeout_time = this.machine.clock.get_time_relative(duration).unwrap_or_else(|| {
305+
this.machine.clock.get_time_relative(Duration::from_secs(3600)).unwrap()
306+
});
308307

309308
let active_thread = this.get_active_thread();
310309
this.block_thread(active_thread);
@@ -330,7 +329,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
330329
let timeout_ms = this.read_scalar(timeout)?.to_u32()?;
331330

332331
let duration = Duration::from_millis(timeout_ms.into());
333-
let timeout_time = this.machine.clock.checked_add_since_now(duration).unwrap();
332+
let timeout_time = this.machine.clock.get_time_relative(duration).unwrap();
334333

335334
let active_thread = this.get_active_thread();
336335
this.block_thread(active_thread);

src/shims/unix/linux/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ pub fn futex<'tcx>(
106106
if op & futex_realtime != 0 {
107107
Time::RealTime(SystemTime::UNIX_EPOCH.checked_add(duration).unwrap())
108108
} else {
109-
this.machine.clock.checked_add_since_start(duration).unwrap()
109+
this.machine.clock.get_time_absolute(duration).unwrap()
110110
}
111111
} else {
112112
// FUTEX_WAIT uses a relative timestamp.
113113
if op & futex_realtime != 0 {
114114
Time::RealTime(SystemTime::now().checked_add(duration).unwrap())
115115
} else {
116-
this.machine.clock.checked_add_since_now(duration).unwrap()
116+
this.machine.clock.get_time_relative(duration).unwrap()
117117
}
118118
})
119119
};

src/shims/unix/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
859859
let timeout_time = if clock_id == this.eval_libc_i32("CLOCK_REALTIME")? {
860860
Time::RealTime(SystemTime::UNIX_EPOCH.checked_add(duration).unwrap())
861861
} else if clock_id == this.eval_libc_i32("CLOCK_MONOTONIC")? {
862-
this.machine.clock.checked_add_since_start(duration).unwrap()
862+
this.machine.clock.get_time_absolute(duration).unwrap()
863863
} else {
864864
throw_unsup_format!("unsupported clock id: {}", clock_id);
865865
};

0 commit comments

Comments
 (0)