read-decrement-write locked

This commit is contained in:
Ac_K 2018-07-19 05:57:54 +02:00
commit 6be0c1ae89

View file

@ -35,20 +35,38 @@ namespace Ryujinx.HLE.OsHle.Kernel
ulong Timeout, ulong Timeout,
bool ShouldDecrement) bool ShouldDecrement)
{ {
Memory.SetExclusive(ThreadState, Address);
int CurrentValue = Memory.ReadInt32(Address); int CurrentValue = Memory.ReadInt32(Address);
while (true)
{
if (Memory.TestExclusive(ThreadState, Address))
{
if (CurrentValue < Value) if (CurrentValue < Value)
{ {
if (ShouldDecrement) if (ShouldDecrement)
{ {
Memory.WriteInt32(Address, CurrentValue - 1); Memory.WriteInt32(Address, CurrentValue - 1);
} }
Memory.ClearExclusiveForStore(ThreadState);
} }
else else
{ {
Memory.ClearExclusiveForStore(ThreadState);
return MakeError(ErrorModule.Kernel, KernelErr.InvalidState); return MakeError(ErrorModule.Kernel, KernelErr.InvalidState);
} }
break;
}
Memory.SetExclusive(ThreadState, Address);
CurrentValue = Memory.ReadInt32(Address);
}
if (Timeout == 0) if (Timeout == 0)
{ {
return MakeError(ErrorModule.Kernel, KernelErr.Timeout); return MakeError(ErrorModule.Kernel, KernelErr.Timeout);