* Provides timers. */
| 35 | * Provides timers. |
| 36 | */ |
| 37 | class Clock |
| 38 | { |
| 39 | public: |
| 40 | /** |
| 41 | * Initialize the clock with the specified callback that will be |
| 42 | * invoked whenever a batch of timers has expired. |
| 43 | */ |
| 44 | // TODO(benh): Introduce a "channel" or listener pattern for getting |
| 45 | // the expired Timers rather than passing in a callback. This might |
| 46 | // mean we don't need 'initialize' or 'shutdown'. |
| 47 | static void initialize( |
| 48 | lambda::function<void(const std::list<Timer>&)>&& callback); |
| 49 | |
| 50 | /** |
| 51 | * Clears all timers without executing them. |
| 52 | * |
| 53 | * The process manager must be properly finalized before the clock is |
| 54 | * finalized. This will eliminate the need for timers to activate and |
| 55 | * prevent further timers from being added after finalization. |
| 56 | * |
| 57 | * Also, the Clock must not be paused when finalizing. |
| 58 | */ |
| 59 | static void finalize(); |
| 60 | |
| 61 | /** |
| 62 | * The current clock time for either the current process that makes |
| 63 | * this call or the global clock time if not invoked from a process. |
| 64 | * |
| 65 | * @return This process' current clock time or the global clock time |
| 66 | * if not invoked from a process. |
| 67 | */ |
| 68 | static Time now(); |
| 69 | |
| 70 | static Time now(ProcessBase* process); |
| 71 | |
| 72 | static Timer timer( |
| 73 | const Duration& duration, |
| 74 | const lambda::function<void()>& thunk); |
| 75 | |
| 76 | static bool cancel(const Timer& timer); |
| 77 | |
| 78 | /** |
| 79 | * Pauses the clock e.g. for testing purposes. |
| 80 | */ |
| 81 | static void pause(); |
| 82 | |
| 83 | /** |
| 84 | * Check whether clock is currently running. |
| 85 | */ |
| 86 | static bool paused(); |
| 87 | |
| 88 | static void resume(); |
| 89 | |
| 90 | static void advance(const Duration& duration); |
| 91 | static void advance(ProcessBase* process, const Duration& duration); |
| 92 | |
| 93 | static void update(const Time& time); |
| 94 |
nothing calls this directly
no outgoing calls
no test coverage detected