class SyntheticClockRealm

Defined at line 28 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.h

Creates and controls a collection of synthetic clocks and timers. Each realm has its own,

isolated, synthetic monotonic clock, which advances on demand (see `AdvanceTo` and `AdvanceBy`).

Within a realm, all clocks and timers advance atomically relative to the realm's synthetic

montonic clock.

All methods are safe to call from any thread.

Public Methods

std::shared_ptr<SyntheticClockRealm> Create ()

Create a new realm with `now() == zx::time(0)`.

Defined at line 16 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc

std::shared_ptr<SyntheticClock> CreateClock (std::string_view name, uint32_t domain, bool adjustable, media::TimelineFunction to_clock_mono)

Creates a new clock. The clock starts starts with the given `to_clock_mono` transformation (by

default, the identity transform).

Defined at line 23 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc

std::shared_ptr<SyntheticTimer> CreateTimer ()

Creates a new timer.

Defined at line 29 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc

zx::time now ()

The current synthetic monotonic time.

Defined at line 40 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc

void AdvanceTo (zx::time mono_now)

Advances `now` to the given monotonic time. Time advances in increments, using the following

procedure:

1. Wait until every non-stopped timer `i` is blocked in `SleepUntil(t_i)`.

2. If any timer has a shutdown or event bit set, wake those timers and goto 1. Else goto 3.

3. Set `now` to the minimum of all `t_i` and `mono_now`.

4. If any timer has `t_i == now`, wake those timers and goto 1. Else stop.

This procedure ensures that time advances deterministically. Timers must eventually block in

`SleepUntil` or be `Stop`ed, otherwise AdvanceTo will deadlock. It is legal to call

`AdvanceTo(now())`. This runs all pending events without advancing time.

Requires: `mono_now >= now()`

Defined at line 45 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc

void AdvanceBy (zx::duration mono_diff)

Advances `now` by the given duration. This is equivalent to `AdvanceTo(now() + mono_diff)` but

executed atomically.

Requires: `mono_diff > 0`

Defined at line 50 of file ../../src/media/audio/lib/clock/synthetic_clock_realm.cc