[#absl-SimulatedClock] = xref:absl.adoc[absl]::SimulatedClock :relfileprefix: ../ :mrdocs: 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>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class SimulatedClock : public xref:absl/Clock.adoc[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 [cols="1,4"] |=== | Name| Description | `xref:absl/Clock.adoc[Clock]` | An 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 [cols="1,4"] |=== | Name| Description | xref:absl/SimulatedClock/2constructor-08.adoc[`SimulatedClock`] [.small]#[constructor]# | Constructors | xref:absl/SimulatedClock/2destructor.adoc[`~SimulatedClock`] [.small]#[destructor]# [.small]#[virtual]# | Destroys the simulated clock. | xref:absl/SimulatedClock/AdvanceTime.adoc[`AdvanceTime`] | Advances the simulated time by the specified duration. Wakes up any threads whose sleeps have now expired. Returns the number of woken threads. | xref:absl/SimulatedClock/AwaitWithDeadline.adoc[`AwaitWithDeadline`] [.small]#[virtual]# | Blocks until the condition is true or until the simulated clock is advanced to or beyond the wakeup time (or both). | xref:absl/SimulatedClock/GetEarliestWakeupTime.adoc[`GetEarliestWakeupTime`] | Returns the earliest wakeup time. | xref:absl/SimulatedClock/SetTime.adoc[`SetTime`] | Sets the simulated time to the argument. Wakes up any threads whose sleeps have now expired. Returns the number of woken threads. | xref:absl/SimulatedClock/Sleep.adoc[`Sleep`] [.small]#[virtual]# | Sleeps until the specified duration has elapsed according to this clock. | xref:absl/SimulatedClock/SleepUntil.adoc[`SleepUntil`] [.small]#[virtual]# | Sleeps until the specified wakeup_time. | xref:absl/SimulatedClock/TimeNow.adoc[`TimeNow`] [.small]#[virtual]# | Returns the simulated time. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Clock/GetRealClock.adoc[`GetRealClock`] | Returns a reference to the global realtime clock. The returned clock is thread‐safe. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#