diff --git a/Source/Threading/AuWakeOnAddress.cpp b/Source/Threading/AuWakeOnAddress.cpp index b094b7e9..2e722f42 100644 --- a/Source/Threading/AuWakeOnAddress.cpp +++ b/Source/Threading/AuWakeOnAddress.cpp @@ -81,7 +81,9 @@ namespace Aurora::Threading bool WaitEntry::SleepOn(WaitState &state) { + #if !defined(WOA_SEMAPHORE_MODE) AU_LOCK_GUARD(this->mutex); + #endif if (state.qwNanosecondsAbs) { @@ -100,8 +102,6 @@ namespace Aurora::Threading return true; } - auto uTimeRemNS = uEndTime - uNow; - #if defined(AURORA_PLATFORM_WIN32) Win32DropSchedulerResolution(); #endif @@ -112,7 +112,12 @@ namespace Aurora::Threading } else { + #if defined(WOA_SEMAPHORE_MODE) + this->semaphore->LockAbsNS(uEndTime); + #else + auto uTimeRemNS = uEndTime - uNow; this->variable.WaitForSignalNsEx(&this->mutex, uTimeRemNS); + #endif } uNow = AuTime::SteadyClockNS(); @@ -130,7 +135,11 @@ namespace Aurora::Threading } else { + #if defined(WOA_SEMAPHORE_MODE) + this->semaphore->Lock(); + #else this->variable.WaitForSignalNsEx(&this->mutex, 0); + #endif } } @@ -147,7 +156,11 @@ namespace Aurora::Threading return false; } + #if defined(WOA_SEMAPHORE_MODE) + this->semaphore->Unlock(1); + #else this->variable.Signal(); + #endif return true; } @@ -262,10 +275,12 @@ namespace Aurora::Threading decltype(pCurrentHead) pLast {}; while (pCurrentHead) { + #if !defined(WOA_SEMAPHORE_MODE) // Insertion barrier { AU_LOCK_GUARD(pCurrentHead->mutex); } + #endif auto [bCont, bRemove] = callback(*pCurrentHead); diff --git a/Source/Threading/AuWakeOnAddress.hpp b/Source/Threading/AuWakeOnAddress.hpp index fdb1a8a6..7dab5c79 100644 --- a/Source/Threading/AuWakeOnAddress.hpp +++ b/Source/Threading/AuWakeOnAddress.hpp @@ -47,8 +47,19 @@ namespace Aurora::Threading WaitEntry *pBefore {}; // synch + #if defined(WOA_SEMAPHORE_MODE) + #if defined(WOA_SEMAPHORE_SEMAPHORE) + // PORT: MacOS (?) + WOA_SEMAPHORE_SEMAPHORE semaphore; + #else + // Testing: + Primitives::Semaphore semaphore; + #endif + #else + // Recommended (we can better filter spurious wakes for the cost of a barrier on signal): Primitives::ConditionMutexInternal mutex; // mutex ctor must come before var Primitives::ConditionVariableInternal variable; // ...and something all 2007+ micro and monolithic kernels should have to yield for an event + #endif // state const void *pAddress {};