2015-10-16 02:46:17 +02:00
|
|
|
#include "LoopThread.h"
|
2015-10-17 03:08:56 +02:00
|
|
|
#include "../logging/logging.h"
|
|
|
|
|
|
|
|
using namespace cpputils::logging;
|
2015-10-16 02:46:17 +02:00
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
|
|
|
|
LoopThread::LoopThread(): _thread() {}
|
|
|
|
|
|
|
|
LoopThread::~LoopThread() {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoopThread::start() {
|
|
|
|
_thread = boost::thread(std::bind(&LoopThread::main, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoopThread::stop() {
|
|
|
|
_thread.interrupt();
|
|
|
|
_thread.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoopThread::main() {
|
|
|
|
try {
|
|
|
|
while(true) {
|
|
|
|
loopIteration();
|
|
|
|
}
|
|
|
|
} catch (const boost::thread_interrupted &e) {
|
|
|
|
//Do nothing, exit thread.
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
//TODO Think about logging
|
2015-10-17 03:08:56 +02:00
|
|
|
LOG(ERROR) << "LoopThread crashed: " << e.what();
|
2015-10-16 02:46:17 +02:00
|
|
|
} catch (...) {
|
|
|
|
//TODO Think about logging
|
2015-10-17 03:08:56 +02:00
|
|
|
LOG(ERROR) << "LoopThread crashed";
|
2015-10-16 02:46:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|