2016-04-07 02:13:46 +02:00
|
|
|
#include <job/WorkContext.hpp>
|
2014-06-04 12:53:11 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void LoadWorker::start() {
|
|
|
|
while (_running) {
|
|
|
|
_context->workNext();
|
|
|
|
std::this_thread::yield();
|
|
|
|
}
|
2014-06-04 12:53:11 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void WorkContext::workNext() {
|
|
|
|
WorkJob* j = nullptr;
|
2014-08-05 14:41:44 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(_inMutex);
|
2016-07-31 15:57:20 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
if (!_workQueue.empty()) {
|
|
|
|
j = _workQueue.front();
|
|
|
|
_workQueue.pop();
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 14:41:44 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
if (j == nullptr) return;
|
2014-06-04 12:53:11 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
j->work();
|
2014-06-04 12:53:11 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
std::lock_guard<std::mutex> guard(_outMutex);
|
|
|
|
_completeQueue.push(j);
|
2014-06-04 12:53:11 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void WorkContext::update() {
|
|
|
|
std::lock_guard<std::mutex> guard(_outMutex);
|
|
|
|
while (!_completeQueue.empty()) {
|
|
|
|
WorkJob* j = _completeQueue.front();
|
|
|
|
_completeQueue.pop();
|
|
|
|
j->complete();
|
|
|
|
delete j;
|
|
|
|
}
|
|
|
|
}
|