Skip to content

Commit 9458edf

Browse files
committed
add docs
1 parent 368a234 commit 9458edf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub struct Evaluator<'mir, 'tcx> {
293293
/// The table of directory descriptors.
294294
pub(crate) dir_handler: shims::unix::DirHandler,
295295

296-
/// FIXME: docs
296+
/// This machine's monotone clock.
297297
pub(crate) clock: Clock,
298298

299299
/// The set of threads.

src/shims/time.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use crate::*;
88

99
const NANOSECOND_PER_BASIC_BLOCK: u64 = 10;
1010

11+
/// A monotone clock used for `Instant` simulation.
1112
#[derive(Debug)]
1213
pub enum Clock {
1314
Host {
14-
/// The "time anchor" for this machine's monotone clock (for `Instant` simulation).
15+
/// The "time anchor" for this machine's monotone clock.
1516
time_anchor: Instant,
1617
},
1718
Virtual {
@@ -21,6 +22,7 @@ pub enum Clock {
2122
}
2223

2324
impl Clock {
25+
/// Create a new clock based on the availability of communication with the host.
2426
pub fn new(communicate: bool) -> Self {
2527
if communicate {
2628
Self::Host { time_anchor: Instant::now() }
@@ -29,6 +31,7 @@ impl Clock {
2931
}
3032
}
3133

34+
/// Get the current time relative to this clock.
3235
pub fn get(&self) -> Duration {
3336
match self {
3437
Self::Host { time_anchor } => Instant::now().saturating_duration_since(*time_anchor),
@@ -37,6 +40,7 @@ impl Clock {
3740
}
3841
}
3942

43+
/// Let the time pass for a small interval.
4044
pub fn tick(&self) {
4145
match self {
4246
Self::Host { .. } => {
@@ -48,6 +52,7 @@ impl Clock {
4852
}
4953
}
5054

55+
/// Sleep for the desired duration.
5156
pub fn sleep(&self, duration: Duration) {
5257
match self {
5358
Self::Host { .. } => std::thread::sleep(duration),
@@ -58,7 +63,7 @@ impl Clock {
5863
}
5964
}
6065

61-
66+
/// Compute `now + duration` relative to this clock.
6267
pub fn checked_add_since_now(&self, duration: Duration) -> Option<Time> {
6368
match self {
6469
Self::Host { .. } => Instant::now().checked_add(duration).map(Time::Monotonic),
@@ -70,6 +75,8 @@ impl Clock {
7075
}
7176
}
7277

78+
/// Compute `start + duration` relative to this clock where `start` is the instant of time when
79+
/// this clock was created.
7380
pub fn checked_add_since_start(&self, duration: Duration) -> Option<Time> {
7481
match self {
7582
Self::Host { time_anchor } => time_anchor.checked_add(duration).map(Time::Monotonic),
@@ -78,6 +85,7 @@ impl Clock {
7885
}
7986
}
8087

88+
/// Assert that this clock is a virtual one and get the current time in nanoseconds.
8189
pub(crate) fn assert_virtual(&self) -> &AtomicU64 {
8290
match self {
8391
Clock::Host { .. } => panic!(),

0 commit comments

Comments
 (0)