DoTask: timed_mutex -> recursive_timed_mutex
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
977a705cd3
commit
b7c7558e1f
@ -8,7 +8,7 @@
|
||||
namespace fortuna {
|
||||
|
||||
auto DoTask::die_pls() -> void {
|
||||
do_sleep.unlock();
|
||||
mtx_do_sleep.unlock();
|
||||
th.join();
|
||||
}
|
||||
|
||||
@ -19,9 +19,12 @@ auto DoTask::thread_pls(const std::chrono::seconds& interval,
|
||||
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)] {
|
||||
while (!do_sleep.try_lock_for(interval)) {
|
||||
while (!mtx_do_sleep.try_lock_for(interval)) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ namespace fortuna {
|
||||
|
||||
class DoTask {
|
||||
private:
|
||||
std::timed_mutex do_sleep;
|
||||
std::recursive_timed_mutex mtx_do_sleep;
|
||||
std::thread th;
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user