Commit 6fe4bc49 authored by Adrien Béraud's avatar Adrien Béraud

scheduled executor: loop waiting

Change-Id: I7ed7da86d14ccad14dc26135c0807b95c88e5367
Reviewed-by: Sébastien Blin's avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 81c0fe40
......@@ -106,11 +106,13 @@ ScheduledExecutor::loop()
std::vector<Job> jobs;
{
std::unique_lock<std::mutex> lock(jobLock_);
if (jobs_.empty())
cv_.wait(lock);
else
cv_.wait_until(lock, jobs_.begin()->first);
if (not running_ or jobs_.empty() or jobs_.begin()->first > clock::now())
while (running_ and (jobs_.empty() or jobs_.begin()->first > clock::now())) {
if (jobs_.empty())
cv_.wait(lock);
else
cv_.wait_until(lock, jobs_.begin()->first);
}
if (not running_)
return;
jobs = std::move(jobs_.begin()->second);
jobs_.erase(jobs_.begin());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment