[*] Harden 1920f5a8 against deadlocks under neverending pipe conditions

This commit is contained in:
Reece Wilson 2024-02-27 10:51:56 +00:00
parent 1920f5a8d5
commit 1f143ae981
4 changed files with 31 additions and 8 deletions

View File

@ -13,5 +13,9 @@ namespace Aurora::IO::CompletionGroup
{ {
virtual bool HasCompletedForGCWI() = 0; virtual bool HasCompletedForGCWI() = 0;
virtual void CleanupForGCWI() = 0; virtual void CleanupForGCWI() = 0;
inline virtual bool HasNonTrivialCleanup()
{
return false;
}
}; };
} }

View File

@ -47,12 +47,17 @@ namespace Aurora::IO::Async
bool APCLessWaitable::HasCompletedForGCWI() bool APCLessWaitable::HasCompletedForGCWI()
{ {
this->CheckLocal();
return this->bHasFinished; return this->bHasFinished;
} }
bool APCLessWaitable::HasNonTrivialCleanup()
{
return true;
}
void APCLessWaitable::CleanupForGCWI() void APCLessWaitable::CleanupForGCWI()
{ {
this->CheckLocal();
AuResetMember(this->pCompletionGroup); AuResetMember(this->pCompletionGroup);
} }

View File

@ -39,6 +39,7 @@ namespace Aurora::IO::Async
virtual bool HasCompletedForGCWI() override; virtual bool HasCompletedForGCWI() override;
virtual void CleanupForGCWI() override; virtual void CleanupForGCWI() override;
virtual bool HasNonTrivialCleanup() override;
bool HasBeenSignaled(); bool HasBeenSignaled();

View File

@ -65,7 +65,7 @@ namespace Aurora::IO::CompletionGroup
void CompletionGroup::DoIOTick(bool bManual) void CompletionGroup::DoIOTick(bool bManual)
{ {
AuList<AuSPtr<ICompletionGroupWorkItem>> removedItems; AuList<AuPair<AuSPtr<ICompletionGroupWorkItem>, bool>> removedItems;
{ {
AU_DEBUG_MEMCRUNCH; AU_DEBUG_MEMCRUNCH;
@ -82,11 +82,19 @@ namespace Aurora::IO::CompletionGroup
this->uTriggered++; this->uTriggered++;
that->CleanupForGCWI();
if (this->pCallbacks) if (that->HasNonTrivialCleanup())
{ {
removedItems.push_back(that); removedItems.push_back(AuMakePair(that, true));
}
else if (this->pCallbacks)
{
removedItems.push_back(AuMakePair(that, false));
that->CleanupForGCWI();
}
else
{
that->CleanupForGCWI();
} }
} }
else else
@ -95,10 +103,10 @@ namespace Aurora::IO::CompletionGroup
} }
} }
} }
if (auto pCallbacks = this->pCallbacks) for (const auto &[pRemoved, bNonTrivial] : removedItems)
{ {
for (const auto &pRemoved : removedItems) if (auto pCallbacks = this->pCallbacks)
{ {
try try
{ {
@ -109,6 +117,11 @@ namespace Aurora::IO::CompletionGroup
SysPushErrorCatch(); SysPushErrorCatch();
} }
} }
if (bNonTrivial)
{
pRemoved->CleanupForGCWI();
}
} }
{ {