2023-11-11 10:11:09 +00:00
|
|
|
/***
|
|
|
|
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"
|
2024-07-12 19:40:05 +00:00
|
|
|
#include <Source/IO/CompletionGroup/CompletionGroup.hpp>
|
2023-11-11 10:11:09 +00:00
|
|
|
|
|
|
|
namespace Aurora::Async
|
|
|
|
{
|
2023-12-01 09:22:51 +00:00
|
|
|
AuSPtr<AuIO::IIOProcessor> ThreadStateSingletons::GetIOProcessor(AuWorkerPId_t pid)
|
|
|
|
{
|
|
|
|
if (this->pIOProcessors)
|
|
|
|
{
|
|
|
|
return this->pIOProcessors;
|
|
|
|
}
|
2023-11-11 10:11:09 +00:00
|
|
|
|
2023-12-01 09:22:51 +00:00
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->mutex);
|
|
|
|
|
|
|
|
if (this->pIOProcessors)
|
|
|
|
{
|
|
|
|
return this->pIOProcessors;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->pIOProcessors = AuIO::NewIOProcessorOnThread(false, pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 19:40:05 +00:00
|
|
|
AuSPtr<AuIO::CompletionGroup::ICompletionGroup> ThreadStateSingletons::GetIOGroup(AuWorkerPId_t pid)
|
2024-07-12 16:22:07 +00:00
|
|
|
{
|
|
|
|
if (this->pGroup)
|
|
|
|
{
|
|
|
|
return this->pGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->mutex);
|
|
|
|
|
|
|
|
if (this->pGroup)
|
|
|
|
{
|
|
|
|
return this->pGroup;
|
|
|
|
}
|
|
|
|
|
2024-07-12 19:40:05 +00:00
|
|
|
this->pGroup = AuIO::CompletionGroup::NewCompletionGroup();
|
|
|
|
|
|
|
|
if (!this->pGroup)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
AuStaticCast<IO::CompletionGroup::CompletionGroup>(this->pGroup)->MakeInternalAsync(pid);
|
|
|
|
|
|
|
|
return this->pGroup;
|
2024-07-12 16:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-01 09:22:51 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-11-11 10:11:09 +00:00
|
|
|
}
|