Fix incorrect return values in OSAtomic

This commit is contained in:
Exzap 2023-06-13 18:32:46 +02:00
parent 808d1bb424
commit 633e5c0e05

View File

@ -33,10 +33,11 @@ namespace coreinit
uint32 OSAddAtomic(std::atomic<uint32be>* mem, uint32 adder) uint32 OSAddAtomic(std::atomic<uint32be>* mem, uint32 adder)
{ {
// used by SDL Wii U port
uint32be knownValue; uint32be knownValue;
while (true) while (true)
{ {
uint32be knownValue = mem->load(); knownValue = mem->load();
uint32be newValue = knownValue + adder; uint32be newValue = knownValue + adder;
if (mem->compare_exchange_strong(knownValue, newValue)) if (mem->compare_exchange_strong(knownValue, newValue))
break; break;
@ -68,7 +69,7 @@ namespace coreinit
uint64be knownValue; uint64be knownValue;
while (true) while (true)
{ {
uint64be knownValue = mem->load(); knownValue = mem->load();
uint64be newValue = knownValue + adder; uint64be newValue = knownValue + adder;
if (mem->compare_exchange_strong(knownValue, newValue)) if (mem->compare_exchange_strong(knownValue, newValue))
break; break;
@ -81,7 +82,7 @@ namespace coreinit
uint64be knownValue; uint64be knownValue;
while (true) while (true)
{ {
uint64be knownValue = mem->load(); knownValue = mem->load();
uint64be newValue = knownValue & val; uint64be newValue = knownValue & val;
if (mem->compare_exchange_strong(knownValue, newValue)) if (mem->compare_exchange_strong(knownValue, newValue))
break; break;
@ -94,7 +95,7 @@ namespace coreinit
uint64be knownValue; uint64be knownValue;
while (true) while (true)
{ {
uint64be knownValue = mem->load(); knownValue = mem->load();
uint64be newValue = knownValue | val; uint64be newValue = knownValue | val;
if (mem->compare_exchange_strong(knownValue, newValue)) if (mem->compare_exchange_strong(knownValue, newValue))
break; break;