libcryfs/random/LoopThread.h
Sebastian Messmer 62fcd1a3fd TODOs
2015-10-29 15:51:05 +01:00

32 lines
881 B
C++

#pragma once
#ifndef MESSMER_CPPUTILS_RANDOM_LOOPTHREAD_H
#define MESSMER_CPPUTILS_RANDOM_LOOPTHREAD_H
#include <boost/thread.hpp>
namespace cpputils {
//TODO Test
//TODO Move out of "random" folder into own library folder
//TODO Test that fork() doesn't destroy anything (e.g. no deadlock on stop() because thread is not running anymore)
// Has to be final, because otherwise there could be a race condition where LoopThreadForkHandler calls a LoopThread
// where the child class destructor already ran.
class LoopThread final {
public:
LoopThread(std::function<void()> loopIteration);
~LoopThread();
void start();
void stop();
void asyncStop();
void waitUntilStopped();
private:
void main();
boost::thread _thread;
std::function<void()> _loopIteration;
};
}
#endif