AuroraRuntime/Source/IO/CompletionGroup/CompletionQuantumEventProvider.cpp

48 lines
1.2 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CompletionQuantumEventProvider.cpp
Date: 2023-12-28
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include "CompletionGroup.hpp"
#include "CompletionQuantumEventProvider.hpp"
namespace Aurora::IO::CompletionGroup
{
CompletionQuantumEventProvider::CompletionQuantumEventProvider(CompletionGroup *pParent, bool bAnd) :
pParent(pParent),
loopSource(pParent, bAnd)
{
}
void CompletionQuantumEventProvider::Set()
{
this->bWasSet = true;
}
AuSPtr<Loop::ILSEvent> CompletionQuantumEventProvider::GetLoopSource()
{
if (!AuThreading::InitOnceLocker::TryLock(&this->initOnce, true))
{
this->initOnce.Wait();
}
else
{
this->bHasInit = this->loopSource.DoInit(this->bWasSet);
AuThreading::InitOnceLocker::Finish(&this->initOnce, !this->bHasInit);
}
if (!this->bHasInit)
{
return {};
}
return AuSPtr<Loop::ILSEvent>(this->pParent->SharedFromThis(),
&this->loopSource);
}
}