diff --git a/Source/Threading/Primitives/AuConditionMutex.NT.cpp b/Source/Threading/Primitives/AuConditionMutex.NT.cpp index 3e4335b1..2311637e 100644 --- a/Source/Threading/Primitives/AuConditionMutex.NT.cpp +++ b/Source/Threading/Primitives/AuConditionMutex.NT.cpp @@ -62,7 +62,7 @@ namespace Aurora::Threading::Primitives { auto &uValueRef = this->lock_.uWaitCount; auto uValue = uValueRef | 1; - + if (AuAtomicCompareExchange(&uValueRef, uValue + kFutexBitWait, uValue) == uValue) { if (gUseNativeWaitCondvar) @@ -89,12 +89,16 @@ namespace Aurora::Threading::Primitives // keep this codeblock in parity // defer to the comments in that source file + auto &uValueRef = this->lock_.uWaitCount; + + #if defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64) + *(AuUInt8 *)&uValueRef = 0; + #else + InterlockedAndRelease((volatile LONG *)&uValueRef, ~0xFF); + #endif + if (gUseNativeWaitCondvar) { - auto &uValueRef = this->lock_.uWaitCount; - - *(AuUInt8 *)&uValueRef = 0; - while (true) { auto uValue = uValueRef; @@ -112,52 +116,45 @@ namespace Aurora::Threading::Primitives SMPPause(); } - return; } - - auto &uValueRef = this->lock_.uWaitCount; - - #if defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64) - *(AuUInt8 *)&uValueRef = 0; - #else - InterlockedAndRelease((volatile LONG *)&uValueRef, ~0xFF); - #endif - - while (true) + else { - auto uOld = uValueRef; - auto uValue = uOld; - - if (uValue & 1) + while (true) { - return; - } + auto uOld = uValueRef; + auto uValue = uOld; - if (uValue < kFutexBitWait) - { - return; - } - - if (uValue & kFutexBitWake) - { - if (AuAtomicCompareExchange(&uValueRef, uValue, uValue) == uValue) + if (uValue & 1) { return; } - else + + if (uValue < kFutexBitWait) { - SMPPause(); - continue; + return; } + + if (uValue & kFutexBitWake) + { + if (AuAtomicCompareExchange(&uValueRef, uValue, uValue) == uValue) + { + return; + } + else + { + SMPPause(); + continue; + } + } + + if (AuAtomicCompareExchange(&uValueRef, uValue - kFutexBitWait + kFutexBitWake, uValue) == uValue) + { + pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&uValueRef, 0, NULL); + return; + } + + SMPPause(); } - - if (AuAtomicCompareExchange(&uValueRef, uValue - kFutexBitWait + kFutexBitWake, uValue) == uValue) - { - pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&uValueRef, 0, NULL); - return; - } - - SMPPause(); } #endif }