gsdx: add atomic for transaction scope object

This commit is contained in:
Gregory Hainaut 2015-02-28 11:01:38 +01:00
parent f904cd6c4a
commit a601991f91
1 changed files with 14 additions and 13 deletions

View File

@ -30,30 +30,31 @@ class TransactionScope
public:
class Lock
{
volatile long state;
std::atomic<bool> state;
public:
Lock()
: state(0)
: state(false)
{
}
void lock()
{
while(_InterlockedCompareExchange(&state, 1, 0) != 0)
bool expected_value = false;
while(state.compare_exchange_strong(expected_value, true))
{
do {_mm_pause();} while(state == 1);
do {_mm_pause();} while(state);
}
}
void unlock()
{
_InterlockedExchange(&state, 0);
state = false;
}
bool isLocked() const
{
return state == 1;
return state.load();
}
};