AuroraRuntime/Source/Async/AuThreadStateSingletons.cpp

87 lines
2.0 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuThreadStateSingletons.cpp
Date: 2023-11-04
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuThreadStateSingletons.hpp"
namespace Aurora::Async
{
AuSPtr<AuIO::IIOProcessor> ThreadStateSingletons::GetIOProcessor(AuWorkerPId_t pid)
{
if (this->pIOProcessors)
{
return this->pIOProcessors;
}
{
AU_LOCK_GUARD(this->mutex);
if (this->pIOProcessors)
{
return this->pIOProcessors;
}
return this->pIOProcessors = AuIO::NewIOProcessorOnThread(false, pid);
}
}
AuSPtr<AuIO::CompletionGroup::ICompletionGroup> ThreadStateSingletons::GetIOGroup()
{
if (this->pGroup)
{
return this->pGroup;
}
{
AU_LOCK_GUARD(this->mutex);
if (this->pGroup)
{
return this->pGroup;
}
return this->pGroup = AuIO::CompletionGroup::NewCompletionGroup();
}
}
void ThreadStateSingletons::TryInitNet(AuWorkerPId_t pid)
{
if (this->pNetInterface)
{
return;
}
AU_LOCK_GUARD(this->mutex);
auto pNetProcessor = AuNet::NewNetworkInterface();
if (!pNetProcessor)
{
return;
}
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(this->GetIOProcessor(pid));
if (!pNetWorker)
{
return;
}
this->pNetWorker = pNetWorker;
this->pNetInterface = pNetProcessor;
}
AuSPtr<AuIO::Net::INetInterface> ThreadStateSingletons::GetIONetInterface(AuWorkerPId_t pid)
{
this->TryInitNet(pid);
return this->pNetInterface;
}
AuSPtr<AuIO::Net::INetWorker> ThreadStateSingletons::GetIONetWorker(AuWorkerPId_t pid)
{
this->TryInitNet(pid);
return this->pNetWorker;
}
}