* Adjusts all periodic timers by adding the specified amount of time to their * next scheduled timestamp. * * @param adjustment The adjustment. */
| 259 | * @param adjustment The adjustment. |
| 260 | */ |
| 261 | void Timer::AdjustTimers(double adjustment) |
| 262 | { |
| 263 | std::unique_lock<std::mutex> lock(l_TimerMutex); |
| 264 | |
| 265 | double now = Utility::GetTime(); |
| 266 | |
| 267 | typedef boost::multi_index::nth_index<TimerSet, 1>::type TimerView; |
| 268 | TimerView& idx = boost::get<1>(l_Timers); |
| 269 | |
| 270 | std::vector<Timer *> timers; |
| 271 | |
| 272 | for (Timer *timer : idx) { |
| 273 | /* Don't schedule the next call if this is not a periodic timer. */ |
| 274 | if (timer->m_Interval <= 0) { |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | if (std::fabs(now - (timer->m_Next + adjustment)) < |
| 279 | std::fabs(now - timer->m_Next)) { |
| 280 | timer->m_Next += adjustment; |
| 281 | timers.push_back(timer); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | for (Timer *timer : timers) { |
| 286 | l_Timers.erase(timer); |
| 287 | l_Timers.insert(timer); |
| 288 | } |
| 289 | |
| 290 | /* Notify the worker that we've rescheduled some timers. */ |
| 291 | l_TimerCV.notify_all(); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Worker thread proc for Timer objects. |