Clock#
Mode#
clock_choice#
:- type clock_choice ---> mock_clock ; live_clock.
Where a session’s two clocks read their time: the capability of ds_clock_mode_t.
Member |
Clocks |
|---|---|
|
moved only by |
|
moved only by |
Under either, the monotonic clock starts at 0 and the wall clock with no value. A session keeps its choice until a replay changes it, as clock_mode states.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.chrono.m)
clock_mode#
:- func clock_mode(session) = read(clock_choice).
The session’s clock choice: the capability of ds_engine_clock_mode.
A replay that delivers a recorded clock sample puts the session on mock_clock, whatever it was loaded with.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.replay.m, Spec: [RFCS.10.5])
Reading#
read_clock#
:- pred read_clock(session::in, session::out, io::di, io::uo) is det.
Under live_clock, reads the host’s monotonic and wall clocks together into the session.
Each reading sets the wall clock to the host’s value, earlier or later. The first leaves the monotonic clock where it is, and each later one moves it forward by the time elapsed, never back.
Under mock_clock, and on a halted session, it changes nothing.
Note
A live_clock does not move between readings. Every input and pump samples the last reading.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.chrono.m, runtime/mercury/src/ds.engine.m, Spec: [LTIM.2.8.3])
now#
:- func now(session) = read(instant).
The monotonic clock’s current value, as a host reads it between calls: the capability of ds_engine_clock_now.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m)
next_deadline#
:- func next_deadline(session) = read(maybe(instant)).
The earliest deadline later than the monotonic clock’s current value, yes(At), or no when the engine holds none: the capability of ds_engine_next_deadline_ns.
It is a read, as now is: it takes no sample, and changes nothing a later call does.
(Source: bindings/mercury/src/mercury_ds.session.m, Spec: [NLFC.2.5])
Moving a mock clock#
advance#
:- pred advance(duration::in, step::out, session::in, session::out) is det.
Moves the mock clocks forward: the capability of ds_engine_clock_advance.
|
Condition |
|---|---|
the session has halted |
|
|
|
|
the advance passes a clock’s range, as |
On success, step_reports holds one ds.clock.advance_total metric and step_duties is empty.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, runtime/mercury/src/ds.chrono.m, Spec: [NMET.4.1], [NTST.3.1])
set_clock#
:- pred set_clock(instant::in, step::out, session::in, session::out) is det.
Sets the mock monotonic clock: the capability of ds_engine_clock_set.
|
Condition |
|---|---|
|
the session has halted |
|
|
|
the instant is above 2^63 - 1, the top of the monotonic clock’s range, before the engine’s first sample or after it; both clocks stay as they were |
|
after the engine’s first sample, the instant is below the current value; both clocks stay as they were |
The first row that applies is the refusal. step_reports and step_duties are empty.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, runtime/mercury/src/ds.chrono.m, Spec: [NTST.3.1])
set_wall_clock#
:- pred set_wall_clock(int64::in, outcome::out, session::in, session::out) is det.
Sets the mock wall clock, in UTC nanoseconds since the Unix epoch, to any instant: the capability of ds_engine_wall_clock_set.
now() faults while the wall clock has no value. The first row that applies is the refusal, and the wall clock stays as it was.
Condition |
|
|---|---|
|
the session has halted |
|
|
:- pred at_epoch(outcome::out, session::in, session::out) is det.
at_epoch(Outcome, !S) :-
set_wall_clock(0i64, Outcome, !S).
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, Spec: [NTST.3.1], [LTIM.2.8.3], [NCBK.2.9])