From b244de73cae2fe11d6913636aa79eba264da9bef Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sun, 1 Jan 2017 21:31:24 +0000 Subject: [PATCH] gsdx: Use separate mutex for waiting In the previous code, the worker thread would notify the MTGS thread while the mutex is still locked, which could cause the MTGS thread to wake up and immediately go back to sleep again since it can't lock the mutex. Use a separate mutex for waiting, which avoids the issue. --- plugins/GSdx/GSThread_CXX11.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/GSdx/GSThread_CXX11.h b/plugins/GSdx/GSThread_CXX11.h index 8587186539..6aa54da977 100644 --- a/plugins/GSdx/GSThread_CXX11.h +++ b/plugins/GSdx/GSThread_CXX11.h @@ -34,6 +34,7 @@ private: ringbuffer_base m_queue; std::mutex m_lock; + std::mutex m_wait_lock; std::condition_variable m_empty; std::condition_variable m_notempty; @@ -64,8 +65,13 @@ private: int32_t old_count = m_count.fetch_sub(consumed); - if (old_count == consumed) + if (old_count == consumed) { + + { + std::lock_guard wait_guard(m_wait_lock); + } m_empty.notify_one(); + } } } @@ -110,7 +116,7 @@ public: void Wait() { if (m_count > 0) { - std::unique_lock l(m_lock); + std::unique_lock l(m_wait_lock); while (m_count > 0) { m_empty.wait(l); }