From b8afde043cbbcbe36574c28ab422c23740f7dc77 Mon Sep 17 00:00:00 2001 From: Tamino Bauknecht Date: Fri, 20 Oct 2023 23:57:51 +0200 Subject: [PATCH] sleeper_thread: allow interrupting sleep() This keeps the function consistent with sleep_until() and sleep_for() which both can be interrupted. This is relevant to allow an update via a "signal" without an "interval" in a custom module. --- include/util/sleeper_thread.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/util/sleeper_thread.hpp b/include/util/sleeper_thread.hpp index 3d8c05d1..80acf169 100644 --- a/include/util/sleeper_thread.hpp +++ b/include/util/sleeper_thread.hpp @@ -61,7 +61,7 @@ class SleeperThread { auto sleep() { std::unique_lock lk(mutex_); CancellationGuard cancel_lock; - return condvar_.wait(lk); + return condvar_.wait(lk, [this] { return signal_ || !do_run_; }); } auto sleep_for(std::chrono::system_clock::duration dur) {