[*] More aggressively wake up reorder prone (unlikely) condvars under broadcast (unlikely)

This commit is contained in:
Reece Wilson 2023-08-26 15:53:13 +01:00
parent 3ca8de022e
commit 346a9f3bde
3 changed files with 27 additions and 30 deletions

View File

@ -124,22 +124,21 @@ namespace Aurora::Threading::Waitables
AuUInt32 uWaitCount {};
AuUInt32 uWaiters {};
uWaiters = AuAtomicLoad(&this->uAtomicSleeping);
if (uWaiters > 0)
while (uWaiters = AuAtomicLoad(&this->uAtomicSleeping))
{
AuAtomicAdd(&this->uAtomicState, uWaiters);
WakeNOnAddress((const void *)&this->uAtomicState, uWaiters);
uWaitCount = uWaiters;
}
while (uWaiters &&
AuAtomicCompareExchange(&this->uAtomicSleeping, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaiters = this->uAtomicSleeping;
if (uWaiters == 0)
while (uWaiters &&
AuAtomicCompareExchange(&this->uAtomicSleeping, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
return;
uWaiters = this->uAtomicSleeping;
if (uWaiters <= uWaitCount)
{
uWaitCount = uWaiters;
}
}
}
}

View File

@ -141,21 +141,20 @@ namespace Aurora::Threading::Primitives
AuUInt32 uWaitCount {};
AuUInt32 uWaiters {};
uWaiters = AuAtomicLoad(&this->uWaiters_);
if (uWaiters > 0)
while (uWaiters = AuAtomicLoad(&this->uWaiters_))
{
this->s_.Unlock(uWaiters);
uWaitCount = uWaiters;
}
while (uWaiters &&
AuAtomicCompareExchange(&this->uWaiters_, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaiters = this->uWaiters_;
if (uWaiters <= uWaitCount)
while (uWaiters &&
AuAtomicCompareExchange(&this->uWaiters_, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaitCount = uWaiters;
uWaiters = this->uWaiters_;
if (uWaiters <= uWaitCount)
{
uWaitCount = uWaiters;
}
}
}
}

View File

@ -163,22 +163,21 @@ namespace Aurora::Threading::Primitives
AuUInt32 uWaitCount {};
AuUInt32 uWaiters {};
uWaiters = AuAtomicLoad(&this->uSleeping_);
if (uWaiters > 0)
while (uWaiters = AuAtomicLoad(&this->uSleeping_))
{
AuAtomicAdd(&this->uState_, uWaiters);
futex_wake(&this->uState_, uWaiters);
uWaitCount = uWaiters;
}
while (uWaiters &&
AuAtomicCompareExchange(&this->uSleeping_, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaiters = this->uSleeping_;
if (uWaiters <= uWaitCount)
while (uWaiters &&
AuAtomicCompareExchange(&this->uSleeping_, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaitCount = uWaiters;
uWaiters = AuAtomicLoad(&this->uSleeping_);
if (uWaiters <= uWaitCount)
{
uWaitCount = uWaiters;
}
}
}
}