Read address atomically in WaitForAddress

We didn't read the values for arbitration atomically in all cases as we should have, this consolidates the reading of the value and uses the value across all cases.
This commit is contained in:
PixelyIon 2022-11-26 00:16:52 +05:30 committed by Mark Collins
parent e8a1bd1aad
commit d0c56235f4

View File

@ -288,14 +288,14 @@ namespace skyline::kernel::type {
{ {
std::scoped_lock lock{syncWaiterMutex}; std::scoped_lock lock{syncWaiterMutex};
u32 userValue{__atomic_load_n(address, __ATOMIC_SEQ_CST)};
switch (type) { switch (type) {
case ArbitrationType::WaitIfLessThan: case ArbitrationType::WaitIfLessThan:
if (*address >= value) [[unlikely]] if (userValue >= value) [[unlikely]]
return result::InvalidState; return result::InvalidState;
break; break;
case ArbitrationType::DecrementAndWaitIfLessThan: { case ArbitrationType::DecrementAndWaitIfLessThan: {
u32 userValue{__atomic_load_n(address, __ATOMIC_SEQ_CST)};
do { do {
if (value <= userValue) [[unlikely]] // We want to explicitly decrement **after** the check if (value <= userValue) [[unlikely]] // We want to explicitly decrement **after** the check
return result::InvalidState; return result::InvalidState;
@ -304,7 +304,7 @@ namespace skyline::kernel::type {
} }
case ArbitrationType::WaitIfEqual: case ArbitrationType::WaitIfEqual:
if (*address != value) [[unlikely]] if (userValue != value) [[unlikely]]
return result::InvalidState; return result::InvalidState;
break; break;
} }