2016-04-07 02:13:46 +02:00
|
|
|
#include <job/WorkContext.hpp>
|
2014-06-04 12:53:11 +02:00
|
|
|
|
|
|
|
void LoadWorker::start()
|
|
|
|
{
|
|
|
|
while( _running ) {
|
|
|
|
_context->workNext();
|
|
|
|
std::this_thread::yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkContext::workNext()
|
|
|
|
{
|
|
|
|
WorkJob* j = nullptr;
|
2014-08-05 14:41:44 +02:00
|
|
|
|
|
|
|
_inMutex.lock();
|
|
|
|
if( ! _workQueue.empty() ) {
|
|
|
|
j = _workQueue.front();
|
|
|
|
_workQueue.pop();
|
2014-06-04 12:53:11 +02:00
|
|
|
}
|
2014-08-05 14:41:44 +02:00
|
|
|
_inMutex.unlock();
|
|
|
|
|
|
|
|
if( j == nullptr ) return;
|
2014-06-04 12:53:11 +02:00
|
|
|
|
|
|
|
j->work();
|
|
|
|
|
2014-08-05 14:41:44 +02:00
|
|
|
_outMutex.lock();
|
|
|
|
_completeQueue.push(j);
|
|
|
|
_outMutex.unlock();
|
2014-06-04 12:53:11 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|