GSdx:SW: Prevent thread ping-pong in software renderer sync

This commit is contained in:
TellowKrinkle 2021-03-28 23:39:25 -05:00 committed by Kojin
parent 85f1acb7b7
commit c3e5b4225b
1 changed files with 26 additions and 7 deletions

View File

@ -17,6 +17,7 @@
#include "GS.h" #include "GS.h"
#include "common/boost_spsc_queue.hpp" #include "common/boost_spsc_queue.hpp"
#include "common/General.h"
template <class T, int CAPACITY> template <class T, int CAPACITY>
class GSJobQueue final class GSJobQueue final
@ -49,13 +50,24 @@ private:
l.unlock(); l.unlock();
uint32 waited = 0;
while (true)
{
while (m_queue.consume_one(*this)) while (m_queue.consume_one(*this))
; waited = 0;
if (waited == 0)
{
{ {
std::lock_guard<std::mutex> wait_guard(m_wait_lock); std::lock_guard<std::mutex> wait_guard(m_wait_lock);
} }
m_empty.notify_one(); m_empty.notify_one();
}
if (waited >= SPIN_TIME_NS)
break;
waited += ShortSpin();
}
l.lock(); l.lock();
} }
@ -97,9 +109,16 @@ public:
} }
void Wait() void Wait()
{
uint32 waited = 0;
while (true)
{ {
if (IsEmpty()) if (IsEmpty())
return; return;
if (waited >= SPIN_TIME_NS)
break;
waited += ShortSpin();
}
std::unique_lock<std::mutex> l(m_wait_lock); std::unique_lock<std::mutex> l(m_wait_lock);
while (!IsEmpty()) while (!IsEmpty())