An abstract interface representing a Clock, which is an object that can tell you the current time, sleep, and wait for a condition variable.
Synopsis
Declared in <absl/time/clock_interface.h>
class Clock;
Description
This interface allows decoupling code that uses time from the code that creates a point in time. You can use this to your advantage by injecting Clocks into interfaces rather than having implementations call absl::Now() directly.
Implementations of this interface must be thread‐safe.
The Clock::GetRealClock() function returns a reference to the global realtime clock.
Example:
bool IsWeekend(Clock& clock) { absl::Time now = clock.TimeNow(); // ... code to check if 'now' is a weekend. }
// Production code. IsWeekend(Clock::GetRealClock());
// Test code: MyTestClock test_clock(SATURDAY); IsWeekend(test_clock);
Member Functions
Name |
Description |
|
Destroys the clock. |
|
Returns when cond is true or the deadline has passed. Returns true iff cond holds when returning. |
|
Sleeps for the specified duration. |
|
Sleeps until the specified time. |
|
Returns the current time. |
Static Member Functions
Name |
Description |
Returns a reference to the global realtime clock. The returned clock is thread‐safe. |
Derived Classes
Name |
Description |
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. |
Created with MrDocs