From 1be3f480172e29c4121c1134e0cd5fbcd1cf0b4b Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 31 Dec 2016 16:59:38 +0100 Subject: [PATCH] gsdx sw: minor fix on the thread management * Upgrade the counter to signed 32 bits. 16 bits is too small to contains the 64K value. * Read ThreadProc/m_count when the mutex is locked * Use old value of the fetch instead to read back the new value --- plugins/GSdx/GSThread_CXX11.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/GSdx/GSThread_CXX11.h b/plugins/GSdx/GSThread_CXX11.h index 05a9b5889b..71cd9ddda0 100644 --- a/plugins/GSdx/GSThread_CXX11.h +++ b/plugins/GSdx/GSThread_CXX11.h @@ -29,7 +29,7 @@ template class GSJobQueue final private: std::thread m_thread; std::function m_func; - std::atomic m_count; + std::atomic m_count; std::atomic m_exit; ringbuffer_base m_queue; @@ -50,19 +50,21 @@ private: m_notempty.wait(l); } + int32_t nb = m_count + l.unlock(); - int16_t consumed = 0; - for (int16_t nb = m_count; nb >= 0; nb--) { + int32_t consumed = 0; + for (; nb >= 0; nb--) { if (m_queue.consume_one(*this)) consumed++; } l.lock(); - m_count -= consumed; + int32_t old_count = m_count.fetch_sub(consumed); - if (m_count <= 0) + if (old_count == consumed) m_empty.notify_one(); }