[*] Update the FutexSemaphore to wake no more than the requested wake count

[*] Cleanup NTs semaphore
This commit is contained in:
Reece Wilson 2023-12-06 11:14:23 +00:00
parent b35b290afd
commit 8b4ad9795c
2 changed files with 5 additions and 10 deletions

View File

@ -71,7 +71,7 @@ namespace Aurora::Threading::Waitables
if (auto uSleeping = AuAtomicLoad(&this->uAtomicSleeping))
{
WakeNOnAddress((const void *)&this->uAtomicState, uSleeping);
WakeNOnAddress((const void *)&this->uAtomicState, AuMin(uSleeping, uThreads));
}
}

View File

@ -219,10 +219,10 @@ namespace Aurora::Threading::Primitives
return;
}
AuAtomicAdd<AuUInt32>(&this->dwState_, uCount);
if (gUseNativeWaitSemapahore)
{
AuAtomicAdd<AuUInt32>(&this->dwState_, uCount);
if (auto dwSleeping = AuAtomicLoad(this->GetSleepCounter()))
{
if (uCount == 1)
@ -237,14 +237,9 @@ namespace Aurora::Threading::Primitives
}
else
{
// realistically, we cant use the sleep counter optimization trick under windows 7
// we would have to expand our already oversized by 8, 24-byte x86_64 semaphore for a trivial perf boost
// we cant efficiently access the conditions state or atomic guarantees...
AuAtomicAdd<AuUInt32>(&this->dwState_, uCount); // this could be moved anywhere above the unlock, including above the lock.
// do not [re]move this lock fence
{
this->mutex.Lock(); // do not [re]move this lock fence
this->mutex.Lock();
this->mutex.Unlock();
}