diff --git a/Include/Aurora/IO/CompletionGroup/ICompletionGroup.hpp b/Include/Aurora/IO/CompletionGroup/ICompletionGroup.hpp index df70c60e..89618c10 100644 --- a/Include/Aurora/IO/CompletionGroup/ICompletionGroup.hpp +++ b/Include/Aurora/IO/CompletionGroup/ICompletionGroup.hpp @@ -39,6 +39,9 @@ namespace Aurora::IO::CompletionGroup // 0 = indefinite virtual bool WaitForAnyMS(AuUInt32 uTimeoutOrZeroMS = 0) = 0; virtual bool WaitForAllMS(AuUInt32 uTimeoutOrZeroMS = 0) = 0; + + virtual bool IsNeverEnding() = 0; + virtual void SetNeverEnding(bool bValue) = 0; }; AUKN_SYM AuSPtr NewCompletionGroup(); diff --git a/Source/IO/CompletionGroup/CompletionGroup.cpp b/Source/IO/CompletionGroup/CompletionGroup.cpp index ca9fbeac..c5ef5401 100644 --- a/Source/IO/CompletionGroup/CompletionGroup.cpp +++ b/Source/IO/CompletionGroup/CompletionGroup.cpp @@ -55,6 +55,7 @@ namespace Aurora::IO::CompletionGroup } AuResetMember(this->callbackTicks); + this->bTerminated = true; } bool CompletionGroup::HasItemsActive() @@ -62,7 +63,7 @@ namespace Aurora::IO::CompletionGroup return this->workItems.size(); } - void CompletionGroup::DoIOTick() + void CompletionGroup::DoIOTick(bool bManual) { AuList> removedItems; @@ -131,7 +132,8 @@ namespace Aurora::IO::CompletionGroup } } - if (this->workItems.empty()) + if (this->workItems.empty() && + (bManual || !this->bIsNeverEnding)) { this->andPlsDontAllocateFdIfUntouchedEvent.Set(); @@ -175,6 +177,7 @@ namespace Aurora::IO::CompletionGroup void CompletionGroup::AddWorkItem(AuSPtr pCompletable) { + SysAssert(!this->bTerminated, "Completion group already terminated"); AU_LOCK_GUARD(this->mutex); this->workItems.push_back(pCompletable); this->uAdded++; @@ -186,6 +189,16 @@ namespace Aurora::IO::CompletionGroup this->callbackTicks.push_back(AuMakePair(pCallbackInvoker, bAny)); } + bool CompletionGroup::IsNeverEnding() + { + return this->bIsNeverEnding; + } + + void CompletionGroup::SetNeverEnding(bool bValue) + { + this->bIsNeverEnding = bValue; + } + AuSPtr CompletionGroup::ToAndLoopSource() { return this->andPlsDontAllocateFdIfUntouchedEvent.GetLoopSource(); @@ -232,7 +245,7 @@ namespace Aurora::IO::CompletionGroup pSource->Set(); } - this->DoIOTick(); + this->DoIOTick(true); } AuSPtr CompletionGroup::OnCompletion() diff --git a/Source/IO/CompletionGroup/CompletionGroup.hpp b/Source/IO/CompletionGroup/CompletionGroup.hpp index 7e158421..d47a8342 100644 --- a/Source/IO/CompletionGroup/CompletionGroup.hpp +++ b/Source/IO/CompletionGroup/CompletionGroup.hpp @@ -34,7 +34,7 @@ namespace Aurora::IO::CompletionGroup AuPair GetStats() override; void SetCallbacks(const AuSPtr &pCallbacks) override; - void DoIOTick(); + void DoIOTick(bool bManual); void ResetMemoryPins(); bool HasItemsActive(); @@ -43,6 +43,9 @@ namespace Aurora::IO::CompletionGroup void AddCallbackTick(const AuSPtr &pCallbackInvoker, bool bAny); + bool IsNeverEnding() override; + void SetNeverEnding(bool bValue) override; + private: AuMutex mutex; AuCriticalSection cs; @@ -56,5 +59,7 @@ namespace Aurora::IO::CompletionGroup AuUInt32 uAdded {}; AuUInt32 uTriggered {}; bool bNoAny {}; + bool bIsNeverEnding {}; + bool bTerminated {}; }; } \ No newline at end of file diff --git a/Source/IO/CompletionGroup/CompletionGroupAndedIOWorkItem.cpp b/Source/IO/CompletionGroup/CompletionGroupAndedIOWorkItem.cpp index 3b290856..9b06316e 100644 --- a/Source/IO/CompletionGroup/CompletionGroupAndedIOWorkItem.cpp +++ b/Source/IO/CompletionGroup/CompletionGroupAndedIOWorkItem.cpp @@ -23,7 +23,7 @@ namespace Aurora::IO::CompletionGroup void CompletionGroupAndedIOWorkItem::DispatchTask(Async::IWorkItemHandler::ProcessInfo &info) { - this->pParent->DoIOTick(); + this->pParent->DoIOTick(false); if (this->pParent->HasItemsActive()) { diff --git a/Source/IO/CompletionGroup/CompletionGroupLoopSource.cpp b/Source/IO/CompletionGroup/CompletionGroupLoopSource.cpp index 9f97bc8f..55880202 100644 --- a/Source/IO/CompletionGroup/CompletionGroupLoopSource.cpp +++ b/Source/IO/CompletionGroup/CompletionGroupLoopSource.cpp @@ -25,7 +25,7 @@ namespace Aurora::IO::CompletionGroup return false; } - this->pParent->DoIOTick(); + this->pParent->DoIOTick(false); if (this->bIsAnd) { @@ -44,7 +44,7 @@ namespace Aurora::IO::CompletionGroup return false; } - this->pParent->DoIOTick(); + this->pParent->DoIOTick(false); if (this->bIsAnd) {