[*] 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)
if (uWaiters <= uWaitCount)
{
return;
uWaitCount = uWaiters;
}
}
}
}

View File

@ -141,12 +141,10 @@ 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)
@ -159,6 +157,7 @@ namespace Aurora::Threading::Primitives
}
}
}
}
AUKN_SYM ConditionEx *FlexibleConditionVariableNew()
{

View File

@ -163,18 +163,16 @@ 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_;
uWaiters = AuAtomicLoad(&this->uSleeping_);
if (uWaiters <= uWaitCount)
{
@ -182,6 +180,7 @@ namespace Aurora::Threading::Primitives
}
}
}
}
AUKN_SYM IConditionVariable *ConditionVariableNew(const AuSPtr<IConditionMutex> &mutex)
{