| 144 | list<Timer> timedout; |
| 145 | |
| 146 | synchronized (timers_mutex) { |
| 147 | // We pass nullptr to be explicit about the fact that we want the |
| 148 | // global clock time, even though it's unnecessary ('tick' is |
| 149 | // called from the event loop, not a Process context). |
| 150 | Time now = Clock::now(nullptr); |
| 151 | |
| 152 | VLOG(3) << "Handling timers up to " << now; |
| 153 | |
| 154 | foreachkey (const Time& timeout, *timers) { |
| 155 | if (timeout > now) { |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | VLOG(3) << "Have timeout(s) at " << timeout; |
| 160 | |
| 161 | // Need to toggle 'settling' so that we don't prematurely say |
| 162 | // we're settled until after the timers are executed below, |
| 163 | // outside of the critical section. |
| 164 | if (clock::paused) { |
| 165 | clock::settling = true; |
| 166 | } |
| 167 | |
| 168 | timedout.splice(timedout.end(), (*timers)[timeout]); |
| 169 | } |
| 170 | |
| 171 | // Now erase the range of timers that timed out. |
| 172 | timers->erase(timers->begin(), timers->upper_bound(now)); |
| 173 | |
| 174 | // Okay, so the timeout for the next timer should not have fired. |
| 175 | CHECK(timers->empty() || (timers->begin()->first > now)); |
| 176 | |
| 177 | // Remove this tick from the scheduled 'ticks', it may have |
| 178 | // been removed already if the clock was paused / manipulated |
| 179 | // in the interim. |
| 180 | ticks->erase(time); |
| 181 | |
| 182 | // Schedule another "tick" if necessary. |
| 183 | scheduleTick(*timers, ticks); |
| 184 | } |
| 185 | |
| 186 | (*clock::callback)(timedout); |
| 187 |
no test coverage detected