| 28 | std::atomic<timer> next_handle = 1; |
| 29 | |
| 30 | timer cluster::start_timer(timer_callback_t on_tick, uint64_t frequency, timer_callback_t on_stop) { |
| 31 | timer_t new_timer; |
| 32 | |
| 33 | new_timer.handle = next_handle++; |
| 34 | new_timer.next_tick = time(nullptr) + frequency; |
| 35 | new_timer.on_tick = std::move(on_tick); |
| 36 | new_timer.on_stop = std::move(on_stop); |
| 37 | new_timer.frequency = frequency; |
| 38 | |
| 39 | std::lock_guard<std::mutex> l(timer_guard); |
| 40 | next_timer.emplace(new_timer); |
| 41 | |
| 42 | return new_timer.handle; |
| 43 | } |
| 44 | |
| 45 | bool cluster::stop_timer(timer t) { |
| 46 | /* |