2015-11-07 09:00:25 +01:00
|
|
|
#include "LoopThread.h"
|
|
|
|
#include "../logging/logging.h"
|
|
|
|
|
|
|
|
using std::function;
|
|
|
|
using boost::none;
|
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
|
2015-11-12 22:07:20 +01:00
|
|
|
LoopThread::LoopThread(function<bool()> loopIteration): _loopIteration(loopIteration), _runningHandle(none) {
|
2015-11-07 09:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LoopThread::~LoopThread() {
|
|
|
|
if (_runningHandle != none) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoopThread::start() {
|
|
|
|
_runningHandle = ThreadSystem::singleton().start(_loopIteration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoopThread::stop() {
|
|
|
|
if (_runningHandle == none) {
|
|
|
|
throw std::runtime_error("LoopThread is not running");
|
|
|
|
}
|
|
|
|
ThreadSystem::singleton().stop(*_runningHandle);
|
|
|
|
_runningHandle = none;
|
|
|
|
}
|
|
|
|
}
|