[*] 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 uWaitCount {};
AuUInt32 uWaiters {}; AuUInt32 uWaiters {};
uWaiters = AuAtomicLoad(&this->uAtomicSleeping); while (uWaiters = AuAtomicLoad(&this->uAtomicSleeping))
if (uWaiters > 0)
{ {
AuAtomicAdd(&this->uAtomicState, uWaiters); AuAtomicAdd(&this->uAtomicState, uWaiters);
WakeNOnAddress((const void *)&this->uAtomicState, uWaiters); WakeNOnAddress((const void *)&this->uAtomicState, uWaiters);
uWaitCount = uWaiters; uWaitCount = uWaiters;
}
while (uWaiters && while (uWaiters &&
AuAtomicCompareExchange(&this->uAtomicSleeping, uWaiters - uWaitCount, uWaiters) != uWaiters) AuAtomicCompareExchange(&this->uAtomicSleeping, uWaiters - uWaitCount, uWaiters) != uWaiters)
{
uWaiters = this->uAtomicSleeping;
if (uWaiters == 0)
{ {
return; uWaiters = this->uAtomicSleeping;
if (uWaiters <= uWaitCount)
{
uWaitCount = uWaiters;
}
} }
} }
} }

View File

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

View File

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