From 2b39fcd7ddccb0093d470d6692e6db23a2366818 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 21 Jun 2016 08:26:26 +0200 Subject: [PATCH] fix: Use native wait timeout --- include/modules/base.hpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/include/modules/base.hpp b/include/modules/base.hpp index f1b3813e..ae28161e 100644 --- a/include/modules/base.hpp +++ b/include/modules/base.hpp @@ -154,9 +154,9 @@ namespace modules void stop() { + std::lock_guard lck(this->broadcast_lock); log_trace(name()); this->wakeup(); - std::lock_guard lck(this->broadcast_lock); this->enable(false); } @@ -194,15 +194,7 @@ namespace modules void sleep(std::chrono::duration sleep_duration) { std::unique_lock lck(this->sleep_lock); - std::thread sleep_thread([&]{ - auto start = std::chrono::system_clock::now(); - while ((std::chrono::system_clock::now() - start) < sleep_duration) { - std::this_thread::sleep_for(50ms); - } - this->wakeup(); - }); - sleep_thread.detach(); - this->sleep_handler.wait(lck); + this->sleep_handler.wait_for(lck, sleep_duration); } void wakeup()