forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopThread.cpp
More file actions
30 lines (24 loc) · 790 Bytes
/
LoopThread.cpp
File metadata and controls
30 lines (24 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "LoopThread.h"
#include "../logging/logging.h"
using std::function;
using boost::none;
namespace cpputils {
LoopThread::LoopThread(function<bool()> loopIteration, std::string threadName)
: _loopIteration(std::move(loopIteration)), _runningHandle(none), _threadName(std::move(threadName)) {
}
LoopThread::~LoopThread() {
if (_runningHandle != none) {
stop();
}
}
void LoopThread::start() {
_runningHandle = ThreadSystem::singleton().start(_loopIteration, _threadName);
}
void LoopThread::stop() {
if (_runningHandle == none) {
throw std::runtime_error("LoopThread is not running");
}
ThreadSystem::singleton().stop(*_runningHandle);
_runningHandle = none;
}
}