#pragma once #ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_ #define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_PERIODICTASK_H_ #include #include #include namespace blockstore { namespace caching { class PeriodicTask final { public: PeriodicTask(std::function task, double intervalSec); private: void _loopIteration(); std::function _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