mirror of https://github.com/PCSX2/pcsx2.git
common:threading: Port NonblockingMutex to std::atomic_flag
This commit is contained in:
parent
89fad4d3ad
commit
60fe26ff2f
|
@ -222,23 +222,24 @@ namespace Threading
|
|||
class NonblockingMutex
|
||||
{
|
||||
protected:
|
||||
volatile int val;
|
||||
std::atomic_flag val;
|
||||
|
||||
public:
|
||||
NonblockingMutex() : val( false ) {}
|
||||
NonblockingMutex() { val.clear(); }
|
||||
virtual ~NonblockingMutex() throw() {}
|
||||
|
||||
bool TryAcquire() throw()
|
||||
{
|
||||
return !AtomicExchange( val, true );
|
||||
return !val.test_and_set();
|
||||
}
|
||||
|
||||
// Can be done with a TryAcquire/Release but it is likely better to do it outside of the object
|
||||
bool IsLocked()
|
||||
{ return !!val; }
|
||||
{ pxAssertMsg(0, "IsLocked isn't supported for NonblockingMutex"); return false; }
|
||||
|
||||
void Release()
|
||||
{
|
||||
AtomicExchange( val, false );
|
||||
val.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue