1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwlib/source/job/WorkContext.cpp

41 lines
633 B
C++
Raw Normal View History

#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;
_inMutex.lock();
if( ! _workQueue.empty() ) {
j = _workQueue.front();
_workQueue.pop();
2014-06-04 12:53:11 +02:00
}
_inMutex.unlock();
if( j == nullptr ) return;
2014-06-04 12:53:11 +02:00
j->work();
_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;
}
}