mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-23 10:52:38 +01:00
d3084ad721
This involves a few changes. The first changes involve allocating GameWindow and WorkContext on the heap, so that RWGame still owns them but chooses when they're freed. The work queue is given a method to stop the worker thread without destroying the work context, so that subsystems relying on the work context may still function to shut down. Then RWGame is rearranged to cleanup separate subsystems in an order that does not conflict (i.e., stop the work queue, shut down other subsystems, then the renderer, *then* the window.) The window needs to be cleaned up *after* the renderer because it owns the OpenGL context.
42 lines
665 B
C++
42 lines
665 B
C++
#include <job/WorkContext.hpp>
|
|
|
|
void LoadWorker::start()
|
|
{
|
|
while( _running ) {
|
|
_context->workNext();
|
|
std::this_thread::yield();
|
|
}
|
|
}
|
|
|
|
void WorkContext::workNext()
|
|
{
|
|
WorkJob* j = nullptr;
|
|
|
|
{
|
|
std::lock_guard<std::mutex> guard( _inMutex );
|
|
|
|
if( ! _workQueue.empty() ) {
|
|
j = _workQueue.front();
|
|
_workQueue.pop();
|
|
}
|
|
}
|
|
|
|
if( j == nullptr ) return;
|
|
|
|
j->work();
|
|
|
|
std::lock_guard<std::mutex> guard( _outMutex );
|
|
_completeQueue.push(j);
|
|
}
|
|
|
|
void WorkContext::update()
|
|
{
|
|
std::lock_guard<std::mutex> guard( _outMutex );
|
|
while( ! _completeQueue.empty() ) {
|
|
WorkJob* j = _completeQueue.front(); _completeQueue.pop();
|
|
j->complete();
|
|
delete j;
|
|
}
|
|
}
|
|
|