absl::SimulatedClock

A simulated clock is a concrete Clock implementation that does not "tick" on its own. Time is advanced by explicit calls to the AdvanceTime() or SetTime() functions.

Synopsis

Declared in <absl/time/simulated_clock.h>

class SimulatedClock
    : public Clock

Description

Example: absl::SimulatedClock sim_clock; absl::Time now = sim_clock.TimeNow(); // now == absl::UnixEpoch()

now = sim_clock.TimeNow(); // now == absl::UnixEpoch() (still)

sim_clock.AdvanceTime(absl::Seconds(3)); now = sim_clock.TimeNow(); // now == absl::UnixEpoch() + absl::Seconds(3)

This class is thread-safe.

Base Classes

NameDescription
ClockAn abstract interface representing a Clock, which is an object that can tell you the current time, sleep, and wait for a condition variable.

Member Functions

NameDescription
SimulatedClock [constructor]Constructors
~SimulatedClock [destructor] [virtual]Destroys the simulated clock.
AdvanceTime Advances the simulated time by the specified duration. Wakes up any threads whose sleeps have now expired. Returns the number of woken threads.
AwaitWithDeadline [virtual]Blocks until the condition is true or until the simulated clock is advanced to or beyond the wakeup time (or both).
GetEarliestWakeupTime Returns the earliest wakeup time.
SetTime Sets the simulated time to the argument. Wakes up any threads whose sleeps have now expired. Returns the number of woken threads.
Sleep [virtual]Sleeps until the specified duration has elapsed according to this clock.
SleepUntil [virtual]Sleeps until the specified wakeup_time.
TimeNow [virtual]Returns the simulated time.

Static Member Functions

NameDescription
GetRealClock Returns a reference to the global realtime clock. The returned clock is thread-safe.