5#include <condition_variable>
62 using Clock = std::chrono::steady_clock;
100 std::condition_variable
cv_;
void start(HoldSpec spec)
Begin a hold.
bool restart_
Set by extend() to make the timer thread recompute its deadline.
void stop()
Cancel the hold and reap the timer thread.
std::atomic< bool > active_
Read without the lock by isActive() and by the wait loop, so atomic.
std::condition_variable cv_
std::thread timer_thread_
uint32_t currentDurationMs() const
The window currently being counted – extended_ms after a successful extend().
Clock::time_point started_at_
std::chrono::steady_clock Clock
bool extend()
Restart the countdown at spec.extended_ms, measured from now.
uint32_t current_duration_ms_
HoldTimer & operator=(const HoldTimer &)=delete
HoldTimer(const HoldTimer &)=delete
What one hold is: how long, and who to tell.
std::string label
Names this hold in the log ("FIRE", "Flow Test").
std::function< void()> on_expire
Called when the hold ends of its own accord.
uint32_t duration_ms
How long to hold, in milliseconds.
std::function< void(bool)> on_active
true when the hold begins, false when it ends by any path.
uint32_t extended_ms
What extend() restarts the countdown at, measured from the extend call.