[*] More NT Loop Queue fixes

This commit is contained in:
Reece Wilson 2023-10-21 14:19:12 +01:00
parent 5233dc7ac8
commit f9916e0f21
2 changed files with 41 additions and 10 deletions

View File

@ -97,6 +97,8 @@ namespace Aurora::IO::Loop
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
result = handler->OnFinished(this->sourceBase, uPosition++); result = handler->OnFinished(this->sourceBase, uPosition++);
} }
catch (...) catch (...)
@ -124,6 +126,8 @@ namespace Aurora::IO::Loop
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
result = handler->OnFinished(this->sourceBase); result = handler->OnFinished(this->sourceBase);
} }
catch (...) catch (...)
@ -158,6 +162,8 @@ namespace Aurora::IO::Loop
{ {
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
bShouldRemove &= handler->OnFinished(this->sourceBase); bShouldRemove &= handler->OnFinished(this->sourceBase);
} }
catch (...) catch (...)
@ -618,17 +624,21 @@ namespace Aurora::IO::Loop
source.source->OnPresleep(); source.source->OnPresleep();
} }
auto bRet = WaitAllEx(timeout); bool bFinished {};
auto bRet = WaitAllEx(timeout, bFinished);
for (const auto &source : this->loopSourceExs_) if (!bFinished)
{ {
source.source->OnFinishSleep(); for (const auto &source : this->loopSourceExs_)
{
source.source->OnFinishSleep();
}
} }
return bRet; return bRet;
} }
bool LoopQueue::WaitAllEx(AuUInt32 timeout) bool LoopQueue::WaitAllEx(AuUInt32 timeout, bool &bFinished)
{ {
bool bReturnStatus {false}; bool bReturnStatus {false};
bool bTimeout {false}; bool bTimeout {false};
@ -674,6 +684,7 @@ namespace Aurora::IO::Loop
} }
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
bFinished = true;
return false; return false;
} }
} }
@ -724,6 +735,7 @@ namespace Aurora::IO::Loop
if (!StartUserAndTakeOwn()) if (!StartUserAndTakeOwn())
{ {
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
bFinished = true;
return bReturnStatus; return bReturnStatus;
} }
@ -786,6 +798,7 @@ namespace Aurora::IO::Loop
} }
} }
bFinished = true;
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
return bReturnStatus; return bReturnStatus;
@ -982,17 +995,21 @@ namespace Aurora::IO::Loop
source.source->OnPresleep(); source.source->OnPresleep();
} }
auto bRet = WaitAnyNBSpuriousEx(internalEndTime, chuggerIndex, trigger, poll, bTriggerWin32); bool bFinished {};
auto bRet = WaitAnyNBSpuriousEx(internalEndTime, chuggerIndex, trigger, poll, bTriggerWin32, bFinished);
for (const auto &source : this->loopSourceExs_) if (!bFinished)
{ {
source.source->OnFinishSleep(); for (const auto &source : this->loopSourceExs_)
{
source.source->OnFinishSleep();
}
} }
return bRet; return bRet;
} }
bool LoopQueue::WaitAnyNBSpuriousEx(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32) bool LoopQueue::WaitAnyNBSpuriousEx(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32, bool &bFinished)
{ {
bool status {}; bool status {};
DWORD temp; DWORD temp;
@ -1108,6 +1125,7 @@ namespace Aurora::IO::Loop
{ {
StartUserAndTakeOwn(); StartUserAndTakeOwn();
ConsiderEvicitingTimeoutsAll(); ConsiderEvicitingTimeoutsAll();
bFinished = true;
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
return false; return false;
} }
@ -1127,6 +1145,7 @@ namespace Aurora::IO::Loop
if (!StartUserAndTakeOwn()) if (!StartUserAndTakeOwn())
{ {
bFinished = true;
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
return true; return true;
} }
@ -1288,6 +1307,7 @@ namespace Aurora::IO::Loop
} }
bFinished = true;
StartUserAndTakeOwn_Release(); StartUserAndTakeOwn_Release();
return triggeredCount; return triggeredCount;
@ -1359,6 +1379,8 @@ namespace Aurora::IO::Loop
{ {
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
bShouldRemove &= handler->OnFinished(this->msgSource_); bShouldRemove &= handler->OnFinished(this->msgSource_);
} }
catch (...) catch (...)
@ -1372,6 +1394,8 @@ namespace Aurora::IO::Loop
{ {
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
bShouldRemove &= handler->OnFinished(this->msgSource_, i++); bShouldRemove &= handler->OnFinished(this->msgSource_, i++);
} }
catch (...) catch (...)
@ -1384,6 +1408,8 @@ namespace Aurora::IO::Loop
{ {
try try
{ {
AU_DEBUG_REVERSE_MEMCRUNCH;
bShouldRemove &= handler->OnFinished(this->msgSource_); bShouldRemove &= handler->OnFinished(this->msgSource_);
} }
catch (...) catch (...)
@ -1404,6 +1430,11 @@ namespace Aurora::IO::Loop
void LoopQueue::StartUserAndTakeOwn_Release() void LoopQueue::StartUserAndTakeOwn_Release()
{ {
this->isCommitableInFuture_ = false; this->isCommitableInFuture_ = false;
for (const auto &source : this->loopSourceExs_)
{
source.source->OnFinishSleep();
}
if (this->willCommitInFuture_) if (this->willCommitInFuture_)
{ {

View File

@ -42,7 +42,7 @@ namespace Aurora::IO::Loop
AuList<AuSPtr<ILoopSource>> PumpNonblockingEx() override; AuList<AuSPtr<ILoopSource>> PumpNonblockingEx() override;
bool WaitAll(AuUInt32 timeout) override; bool WaitAll(AuUInt32 timeout) override;
bool WaitAllEx(AuUInt32 timeout); bool WaitAllEx(AuUInt32 timeout, bool &bFinished);
AuUInt32 WaitAny(AuUInt32 timeout) override; AuUInt32 WaitAny(AuUInt32 timeout) override;
AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override; AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override;
@ -83,7 +83,7 @@ namespace Aurora::IO::Loop
bool IsValid(); bool IsValid();
bool RemoveSourceNB(const AuSPtr<ILoopSource> &source); bool RemoveSourceNB(const AuSPtr<ILoopSource> &source);
bool WaitAnyNBSpurious(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32); bool WaitAnyNBSpurious(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32);
bool WaitAnyNBSpuriousEx(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32); bool WaitAnyNBSpuriousEx(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32, bool &bFinished);
bool ChugWaitAny(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuUInt32 &offset); bool ChugWaitAny(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuUInt32 &offset);
bool StartUserAndTakeOwn(); bool StartUserAndTakeOwn();