AuroraRuntime/Source/IO/CompletionGroup/CompletionGroup.hpp
2024-01-11 12:19:54 +00:00

65 lines
2.1 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CompletionGroup.hpp
Date: 2023-12-28
Author: Reece
***/
#pragma once
#include "CompletionQuantumEventProvider.hpp"
namespace Aurora::IO::CompletionGroup
{
struct CompletionGroup :
AuEnableSharedFromThis<CompletionGroup>,
ICompletionGroup
{
CompletionGroup();
~CompletionGroup();
AuSPtr<Loop::ILoopSource> ToAndLoopSource() override;
AuSPtr<Loop::ILoopSource> ToAnyLoopSource() override;
AuSPtr<Async::IWorkItem> OnCompletion() override;
AuSPtr<Async::IWorkItem> OnSingleCompletion() override;
bool WaitForAnyMS(AuUInt32 uTimeoutOrZeroMS) override;
bool WaitForAllMS(AuUInt32 uTimeoutOrZeroMS) override;
AuSPtr<Loop::ILSEvent> GetTriggerLoopSource() override;
void TryTrigger() override;
bool HasCompleted() override;
AuPair<AuUInt32, AuUInt32> GetStats() override;
void SetCallbacks(const AuSPtr<ICompletionGroupHooks> &pCallbacks) override;
void DoIOTick(bool bManual);
void ResetMemoryPins();
bool HasItemsActive();
void AddWorkItem(AuSPtr<ICompletionGroupWorkItem> pCompletable) override;
void AddCallbackTick(const AuSPtr<IIOProcessorManualInvoker> &pCallbackInvoker, bool bAny);
bool IsNeverEnding() override;
void SetNeverEnding(bool bValue) override;
private:
AuMutex mutex;
AuCriticalSection cs;
CompletionQuantumEventProvider anyProbablyAlwaysPresentEvent;
CompletionQuantumEventProvider andPlsDontAllocateFdIfUntouchedEvent;
AuList<AuSPtr<ICompletionGroupWorkItem>> workItems;
AuSPtr<ICompletionGroupHooks> pCallbacks;
AuSPtr<Async::IWorkItem> pAnyBarrier;
AuSPtr<Async::IWorkItem> pAndBarrier;
AuList<AuPair<AuSPtr<IIOProcessorManualInvoker>, bool>> callbackTicks;
AuUInt32 uAdded {};
AuUInt32 uTriggered {};
bool bNoAny {};
bool bIsNeverEnding {};
bool bTerminated {};
};
}