Utilities: Add TryWait and spin waits to semaphore and mutex

This commit is contained in:
TellowKrinkle
2021-03-28 03:09:52 -05:00
committed by Kojin
parent 5ff89dd695
commit 881b017606
4 changed files with 47 additions and 0 deletions

View File

@@ -28,6 +28,7 @@
#endif
#include "common/Pcsx2Defs.h"
#include "common/TraceLog.h"
#include "common/General.h"
#undef Yield // release the burden of windows.h global namespace spam.
@@ -256,6 +257,20 @@ namespace Threading
bool WaitWithoutYield(const wxTimeSpan& timeout);
void WaitNoCancel();
void WaitNoCancel(const wxTimeSpan& timeout);
void WaitWithoutYieldWithSpin()
{
u32 waited = 0;
while (true)
{
if (TryWait())
return;
if (waited >= SPIN_TIME_NS)
break;
waited += ShortSpin();
}
WaitWithoutYield();
}
bool TryWait();
int Count();
void Wait();
@@ -285,6 +300,7 @@ namespace Threading
bool AcquireWithoutYield(const wxTimeSpan& timeout);
void Wait();
void WaitWithSpin();
bool Wait(const wxTimeSpan& timeout);
void WaitWithoutYield();
bool WaitWithoutYield(const wxTimeSpan& timeout);