gl: Fix a fence deadlock in fence::wait_for_signal

gl: Fix potential race condition when executing local work queue
This commit is contained in:
kd-11 2017-02-27 23:53:34 +03:00
parent cee53fcecf
commit 7062efeb3e
4 changed files with 9 additions and 7 deletions

View file

@ -942,6 +942,8 @@ void GLGSRender::do_local_task()
{
std::lock_guard<std::mutex> lock(queue_guard);
work_queue.remove_if([](work_item &q) { return q.received; });
for (work_item& q: work_queue)
{
std::unique_lock<std::mutex> lock(q.guard_mutex);
@ -954,8 +956,6 @@ void GLGSRender::do_local_task()
lock.unlock();
q.cv.notify_one();
}
work_queue.clear();
}
work_item& GLGSRender::post_flush_request(u32 address)

View file

@ -17,9 +17,10 @@ struct work_item
std::condition_variable cv;
std::mutex guard_mutex;
u32 address_to_flush;
bool processed;
bool result;
u32 address_to_flush = 0;
bool processed = false;
bool result = false;
bool received = false;
};
struct gcm_buffer_info

View file

@ -80,6 +80,7 @@ namespace gl
void create()
{
m_value = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
flags = GL_SYNC_FLUSH_COMMANDS_BIT;
}
void destroy()
@ -132,7 +133,7 @@ namespace gl
{
if (flags)
{
err = glClientWaitSync(m_value, flags, 1000);
err = glClientWaitSync(m_value, flags, 0);
flags = 0;
switch (err)

View file

@ -54,7 +54,7 @@ namespace gl
task.cv.wait(lock, [&task] { return task.processed; });
}
verify(HERE), task.result == true;
task.received = true;
return task.result;
}