Adapt to new cpputils

This commit is contained in:
Sebastian Messmer 2015-11-12 13:07:59 -08:00
parent ea9d912a16
commit 06b78f1b80
2 changed files with 4 additions and 3 deletions

View File

@ -15,11 +15,12 @@ PeriodicTask::PeriodicTask(function<void ()> task, double intervalSec) :
_thread.start(); _thread.start();
} }
void PeriodicTask::_loopIteration() { bool PeriodicTask::_loopIteration() {
//Has to be boost::this_thread::sleep_for and not std::this_thread::sleep_for, because it has to be interruptible. //Has to be boost::this_thread::sleep_for and not std::this_thread::sleep_for, because it has to be interruptible.
//LoopThread will interrupt this method if it has to be restarted. //LoopThread will interrupt this method if it has to be restarted.
boost::this_thread::sleep_for(_interval); boost::this_thread::sleep_for(_interval);
_task(); _task();
return true; // Run another iteration (don't terminate thread)
} }
} }

View File

@ -3,7 +3,7 @@
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_ #define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_
#include <functional> #include <functional>
#include <messmer/cpp-utils/random/LoopThread.h> #include <messmer/cpp-utils/thread/LoopThread.h>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
namespace blockstore { namespace blockstore {
@ -14,7 +14,7 @@ public:
PeriodicTask(std::function<void ()> task, double intervalSec); PeriodicTask(std::function<void ()> task, double intervalSec);
private: private:
void _loopIteration(); bool _loopIteration();
std::function<void()> _task; std::function<void()> _task;
boost::chrono::nanoseconds _interval; boost::chrono::nanoseconds _interval;