From c3e5b4225b06db769e9816bb924eb352ec1e3e2c Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sun, 28 Mar 2021 23:39:25 -0500 Subject: [PATCH] GSdx:SW: Prevent thread ping-pong in software renderer sync --- pcsx2/GS/GSThread_CXX11.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pcsx2/GS/GSThread_CXX11.h b/pcsx2/GS/GSThread_CXX11.h index 904912e5ac..497c8c69f7 100644 --- a/pcsx2/GS/GSThread_CXX11.h +++ b/pcsx2/GS/GSThread_CXX11.h @@ -17,6 +17,7 @@ #include "GS.h" #include "common/boost_spsc_queue.hpp" +#include "common/General.h" template class GSJobQueue final @@ -49,13 +50,24 @@ private: l.unlock(); - while (m_queue.consume_one(*this)) - ; - + uint32 waited = 0; + while (true) { - std::lock_guard wait_guard(m_wait_lock); + while (m_queue.consume_one(*this)) + waited = 0; + + if (waited == 0) + { + { + std::lock_guard wait_guard(m_wait_lock); + } + m_empty.notify_one(); + } + + if (waited >= SPIN_TIME_NS) + break; + waited += ShortSpin(); } - m_empty.notify_one(); l.lock(); } @@ -98,8 +110,15 @@ public: void Wait() { - if (IsEmpty()) - return; + uint32 waited = 0; + while (true) + { + if (IsEmpty()) + return; + if (waited >= SPIN_TIME_NS) + break; + waited += ShortSpin(); + } std::unique_lock l(m_wait_lock); while (!IsEmpty())