libcryfs/implementations/caching/cache/PeriodicTask.h
2015-10-28 15:00:49 +01:00

31 lines
712 B
C++

#pragma once
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_
#include <functional>
#include <messmer/cpp-utils/random/LoopThread.h>
#include <boost/chrono.hpp>
namespace blockstore {
namespace caching {
class PeriodicTask final {
public:
PeriodicTask(std::function<void ()> task, double intervalSec);
private:
void _loopIteration();
std::function<void()> _task;
boost::chrono::nanoseconds _interval;
//This member has to be last, so the thread is destructed first. Otherwise the thread might access elements from a
//partly destructed PeriodicTask.
cpputils::LoopThread _thread;
};
}
}
#endif