DoTask: timed_mutex -> recursive_timed_mutex
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-21 02:54:15 +01:00
parent 977a705cd3
commit b7c7558e1f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 7 additions and 4 deletions

@ -8,7 +8,7 @@
namespace fortuna { namespace fortuna {
auto DoTask::die_pls() -> void { auto DoTask::die_pls() -> void {
do_sleep.unlock(); mtx_do_sleep.unlock();
th.join(); th.join();
} }
@ -19,9 +19,12 @@ auto DoTask::thread_pls(const std::chrono::seconds& interval,
die_pls(); die_pls();
} }
do_sleep.lock(); // since this is a std::recursive_timed_mutex, an attempt is made to only
// try_lock() it
mtx_do_sleep.try_lock();
th = std::thread([this, interval, callback = std::move(callback)] { th = std::thread([this, interval, callback = std::move(callback)] {
while (!do_sleep.try_lock_for(interval)) { while (!mtx_do_sleep.try_lock_for(interval)) {
callback(); callback();
} }
}); });

@ -10,7 +10,7 @@ namespace fortuna {
class DoTask { class DoTask {
private: private:
std::timed_mutex do_sleep; std::recursive_timed_mutex mtx_do_sleep;
std::thread th; std::thread th;
public: public: