common:threading: Port NonblockingMutex to std::atomic_flag

This commit is contained in:
Gregory Hainaut 2016-02-22 19:55:39 +01:00
parent 89fad4d3ad
commit 60fe26ff2f
1 changed files with 6 additions and 5 deletions

View File

@ -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();
}
};