mirror of https://github.com/PCSX2/pcsx2.git
gsdx: add atomic for transaction scope object
This commit is contained in:
parent
f904cd6c4a
commit
a601991f91
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue