Fix gradiceks mess.
Summary: Fix fix fix. Reviewers: matej.gradicek Reviewed By: matej.gradicek Differential Revision: https://phabricator.memgraph.io/D245
This commit is contained in:
parent
22dfe61fe1
commit
74740dd162
@ -1,8 +1,8 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include <ctime>
|
||||
#include <thread>
|
||||
|
||||
/**
|
||||
* Class used to run given std::function<void()>. Function is ran and then sleep
|
||||
@ -26,7 +26,7 @@ class Scheduler {
|
||||
// if pause_ equals -1, scheduler will not run
|
||||
if (pause_ == std::chrono::seconds(-1)) return;
|
||||
auto start_time = std::chrono::system_clock::now();
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
if (!is_working_.load()) break;
|
||||
|
||||
func_();
|
||||
@ -34,11 +34,10 @@ class Scheduler {
|
||||
std::unique_lock<std::mutex> lk(mutex_);
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
while(now >= start_time) start_time += pause_;
|
||||
while (now >= start_time) start_time += pause_;
|
||||
|
||||
condition_variable_.wait_for(lk, start_time - now, [&] {
|
||||
return is_working_.load() == false;
|
||||
});
|
||||
condition_variable_.wait_for(
|
||||
lk, start_time - now, [&] { return is_working_.load() == false; });
|
||||
lk.unlock();
|
||||
}
|
||||
});
|
||||
@ -65,7 +64,7 @@ class Scheduler {
|
||||
/**
|
||||
* Function which scheduler executes.
|
||||
*/
|
||||
const std::function <void()> &func_;
|
||||
const std::function<void()> func_;
|
||||
/**
|
||||
* Mutex used to synchronize threads using condition variable.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user