| 28 | } |
| 29 | |
| 30 | void timer::start() { |
| 31 | std::scoped_lock lock{mtx_}; |
| 32 | if (is_value(state_).none_of(state_e::STOPPED, state_e::IN_TASK_STOPPED)) { |
| 33 | // the timer is already running -> restart it |
| 34 | stop_unlocked(); |
| 35 | } |
| 36 | if (is_value(state_).any_of(state_e::IN_TASK, state_e::IN_TASK_STARTED, state_e::IN_TASK_STOPPED)) { |
| 37 | // the timer is currently executing the task |
| 38 | // -> adjust the state but don't do anything, as it will be restarted after being done with |
| 39 | // the task |
| 40 | state_ = state_e::IN_TASK_STARTED; |
| 41 | return; |
| 42 | } |
| 43 | start_unlocked(); |
| 44 | } |
| 45 | |
| 46 | void timer::stop() { |
| 47 | std::scoped_lock lock{mtx_}; |