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

mock_clock

moved only by advance, set_clock and set_wall_clock

live_clock

moved only by read_clock

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)

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.

step_outcome

Condition

error, engine_halted

the session has halted

error, state

clock_mode answers live_clock

error, time_range

the advance passes a clock’s range, as ds_engine_clock_advance states; both clocks stay as they were

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.

step_outcome

Condition

error, engine_halted

the session has halted

error, state

clock_mode answers live_clock; or, after the engine’s first sample, the instant is below the current value, and both clocks stay as they were

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.

outcome

Condition

error, engine_halted

the session has halted

error, state

clock_mode answers live_clock

:- 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])