Helper for determining the time when the next timer elapses, or None if no timers are pending, or the clock is paused and no timers are expired. Note that we don't manipulate 'timers' directly so that it's clear from the callsite that the use of 'timers' is within a 'synchronized' block. TODO(benh): Create a generic 'Timers' abstraction which hides this and more away (i.e., all manipulations of '
| 86 | // TODO(benh): Create a generic 'Timers' abstraction which hides this |
| 87 | // and more away (i.e., all manipulations of 'timers' below). |
| 88 | Option<Time> next(const map<Time, list<Timer>>& timers) |
| 89 | { |
| 90 | if (!timers.empty()) { |
| 91 | Time first = timers.begin()->first; |
| 92 | |
| 93 | // If the clock is paused and no timers are expired, the |
| 94 | // timers cannot fire until the clock is advanced, so we |
| 95 | // return None() here. Note that we pass nullptr to ensure |
| 96 | // that this looks at the global clock, since this can be |
| 97 | // called from a Process context through Clock::timer. |
| 98 | if (Clock::paused() && first > Clock::now(nullptr)) { |
| 99 | return None(); |
| 100 | } |
| 101 | |
| 102 | return first; |
| 103 | } |
| 104 | |
| 105 | return None(); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | // Forward declaration for scheduleTick. |