[*] NT: fix AuLoop::ILoopQueue::WaitAll defects

This commit is contained in:
Reece Wilson 2024-09-21 00:49:01 +01:00
parent 888e255cca
commit 36349b4d02

View File

@ -654,7 +654,7 @@ namespace Aurora::IO::Loop
count = this->handleArrayAnd_.size();
AuUInt64 startTime = AuTime::SteadyClockNS();
AuUInt64 endTime = startTime + AuMSToNS<AuUInt64>(timeout);
AuUInt64 endTime = timeout ? startTime + AuMSToNS<AuUInt64>(timeout) : 0;
while (count != index)
{
@ -662,16 +662,30 @@ namespace Aurora::IO::Loop
startTime = AuTime::SteadyClockNS();
if (timeout)
AuUInt32 timeDelta {};
if (!timeout)
{
if (endTime <= startTime)
timeDelta = INFINITE;
}
else
{
if (endTime > startTime)
{
timeDelta = AuNSToMS<AuUInt32>(endTime - startTime);
}
else if (endTime == startTime)
{
}
else
{
Iterator queueIterator(this);
for (queueIterator.Start(); queueIterator.End() != queueIterator.itr; )
{
auto &source = *queueIterator.itr;
if (queueIterator.startingIndexAnd > index)
if (queueIterator.startingIndexAnd >= index)
{
break;
}
@ -691,12 +705,14 @@ namespace Aurora::IO::Loop
bFinished = true;
return false;
}
if (!timeDelta)
{
timeDelta = 1;
}
}
auto timeDelta = AuNSToMS<AuUInt32>(endTime - startTime); // TODO: cap to last obj
DWORD status {};
do
{
if (this->bIsWinLoop_ &&
@ -758,11 +774,6 @@ namespace Aurora::IO::Loop
bShouldRemove = true;
}
if (ticked)
{
bReturnStatus |= true;
}
if (this->handleArrayOr_[queueIterator.startingIndexOr] == AuReinterpretCast<HANDLE>(this->hDummy_))
{
auto handle = AuReinterpretCast<HANDLE>(source.source->Singular() ? source.source->GetHandle() : source.source->GetHandles()[0]);
@ -770,6 +781,72 @@ namespace Aurora::IO::Loop
this->handleArrayOr_[queueIterator.startingIndexOr] = handle;
}
if (!bShouldRemove && !ticked)
{
bool bCompletedInTimeout = { };
AuUInt64 uStartTime {};
do
{
if (!source.timeoutAbs)
{
bCompletedInTimeout = source.source->WaitOnAbsExt(0, endTime);
}
else
{
bCompletedInTimeout = source.source->WaitOnAbsExt(0, !endTime ? AuMSToNS<AuUInt64>(source.timeoutAbs) : AuMin(endTime, AuMSToNS<AuUInt64>(source.timeoutAbs)));
}
if (bCompletedInTimeout)
{
AuTupleTie(ticked, bShouldRemove) = source.DoWork(this, -1);
if (!ticked)
{
bCompletedInTimeout = false;
}
}
}
while (!bCompletedInTimeout && (!timeout || ((uStartTime = AuTime::SteadyClockNS()) < endTime)));
if (!bCompletedInTimeout)
{
Iterator queueIterator2(this);
for (queueIterator2.Start(); queueIterator2.End() != queueIterator2.itr; )
{
auto &source = *queueIterator2.itr;
if (queueIterator2.startingIndexAnd >= index)
{
break;
}
if (queueIterator2.itr->source)
{
ResetLoopSourceFalseAlarm(queueIterator2.itr->source);
}
queueIterator2.Next();
}
if (StartUserAndTakeOwn())
{
ConsiderEvicitingTimeoutsAll();
StartUserAndTakeOwn_Release();
}
return false;
}
else
{
ticked = true;
}
}
if (ticked)
{
bReturnStatus |= true;
}
if (bShouldRemove)
{
AuStaticCast<ILoopSourceEx>(source.source)->OnFinishSleep();