/*** Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuThreadStateSingletons.cpp Date: 2023-11-04 Author: Reece ***/ #include #include "AuThreadStateSingletons.hpp" #include namespace Aurora::Async { AuSPtr 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 ThreadStateSingletons::GetIOGroup(AuWorkerPId_t pid) { if (this->pGroup) { return this->pGroup; } { AU_LOCK_GUARD(this->mutex); if (this->pGroup) { return this->pGroup; } this->pGroup = AuIO::CompletionGroup::NewCompletionGroup(); if (!this->pGroup) { return {}; } AuStaticCast(this->pGroup)->MakeInternalAsync(pid); return this->pGroup; } } 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 ThreadStateSingletons::GetIONetInterface(AuWorkerPId_t pid) { this->TryInitNet(pid); return this->pNetInterface; } AuSPtr ThreadStateSingletons::GetIONetWorker(AuWorkerPId_t pid) { this->TryInitNet(pid); return this->pNetWorker; } }