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();
while (m_queue.consume_one(*this)) uint32 waited = 0;
; while (true)
{ {
std::lock_guard<std::mutex> wait_guard(m_wait_lock); while (m_queue.consume_one(*this))
waited = 0;
if (waited == 0)
{
{
std::lock_guard<std::mutex> wait_guard(m_wait_lock);
}
m_empty.notify_one();
}
if (waited >= SPIN_TIME_NS)
break;
waited += ShortSpin();
} }
m_empty.notify_one();
l.lock(); l.lock();
} }
@ -98,8 +110,15 @@ public:
void Wait() void Wait()
{ {
if (IsEmpty()) uint32 waited = 0;
return; while (true)
{
if (IsEmpty())
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())