| 183 | |
| 184 | private: |
| 185 | void run() |
| 186 | { |
| 187 | while(!m_finish.load()) |
| 188 | { |
| 189 | auto end = calcWaitTime(); |
| 190 | if(end.first) |
| 191 | { |
| 192 | // Timers found, so wait until it expires (or something else |
| 193 | // changes) |
| 194 | m_checkWork.waitUntil(end.second); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | // No timers exist, so wait an arbitrary amount of time |
| 199 | m_checkWork.waitUntil(ClockT::now() + std::chrono::milliseconds(10)); |
| 200 | } |
| 201 | |
| 202 | // Check and execute as much work as possible, such as, all expired |
| 203 | // timers |
| 204 | checkWork(); |
| 205 | } |
| 206 | |
| 207 | // If we are shutting down, we should not have any items left, |
| 208 | // since the shutdown cancels all items |
| 209 | assert(m_items.size() == 0); |
| 210 | } |
| 211 | |
| 212 | std::pair<bool, std::chrono::time_point<ClockT, DurationT>> calcWaitTime() |
| 213 | { |