diff --git a/Include/Aurora/Async/Async.hpp b/Include/Aurora/Async/Async.hpp index 6fce5074..30cc915a 100644 --- a/Include/Aurora/Async/Async.hpp +++ b/Include/Aurora/Async/Async.hpp @@ -61,6 +61,11 @@ namespace Aurora::Async AUKN_SYM AuSPtr NewThreadPool(); AUKN_SYM void SetMainThreadForSysPumpScheduling(WorkerPId_t pid); + + AUKN_SYM AuSPtr GetSelfIOProcessor(); + AUKN_SYM AuSPtr GetSelfIONetInterface(); + AUKN_SYM AuSPtr GetSelfIONetWorker(); + AUKN_SYM AuSPtr GetSelfIOGroup(); } #if !defined(_CPPSHARP) diff --git a/Include/Aurora/Async/IThreadPool.hpp b/Include/Aurora/Async/IThreadPool.hpp index ac6552de..7c178df2 100644 --- a/Include/Aurora/Async/IThreadPool.hpp +++ b/Include/Aurora/Async/IThreadPool.hpp @@ -19,6 +19,11 @@ namespace Aurora::IO::Net struct INetWorker; } +namespace Aurora::IO::CompletionGroup +{ + struct ICompletionGroup; +} + namespace Aurora::Async { struct IThreadPool @@ -87,10 +92,7 @@ namespace Aurora::Async virtual AuSPtr GetIOProcessor(WorkerId_t id) = 0; virtual AuSPtr GetIONetInterface(WorkerId_t id) = 0; virtual AuSPtr GetIONetWorker(WorkerId_t id) = 0; - - static AuSPtr GetSelfIOProcessor(); - static AuSPtr GetSelfIONetInterface(); - static AuSPtr GetSelfIONetWorker(); + virtual AuSPtr GetIOGroup(WorkerId_t id) = 0; // Synchronization diff --git a/Include/Aurora/IO/IAsyncTransaction.hpp b/Include/Aurora/IO/IAsyncTransaction.hpp index 7b586f00..551788c7 100644 --- a/Include/Aurora/IO/IAsyncTransaction.hpp +++ b/Include/Aurora/IO/IAsyncTransaction.hpp @@ -17,6 +17,11 @@ namespace Aurora::IO::CompletionGroup struct ICompletionGroup; } +namespace Aurora::Async +{ + AUKN_SYM AuSPtr GetSelfIOGroup(); +} + #include "CompletionGroup/ICompletionGroupWorkHandle.hpp" #include @@ -132,6 +137,10 @@ namespace Aurora::IO { (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); } + else if (auto pGroup = Aurora::Async::GetSelfIOGroup()) + { + (void)pTransaction->TryAttachToCompletionGroup(pGroup); + } if (callback) { @@ -157,6 +166,10 @@ namespace Aurora::IO { (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); } + else if (auto pGroup = Aurora::Async::GetSelfIOGroup()) + { + (void)pTransaction->TryAttachToCompletionGroup(pGroup); + } if (callback) { diff --git a/Source/Async/Async.cpp b/Source/Async/Async.cpp index 6fdd798f..658ee5b9 100644 --- a/Source/Async/Async.cpp +++ b/Source/Async/Async.cpp @@ -23,4 +23,56 @@ namespace Aurora::Async DeinitSched(); ReleaseApp(); } + + AuSPtr GetSelfIOProcessor() + { + auto pid = GetCurrentWorkerPId(); + if (pid) + { + return pid.GetPool()->GetIOProcessor(pid); + } + else + { + return {}; + } + } + + AuSPtr GetSelfIONetInterface() + { + auto pid = GetCurrentWorkerPId(); + if (pid) + { + return pid.GetPool()->GetIONetInterface(pid); + } + else + { + return {}; + } + } + + AuSPtr GetSelfIONetWorker() + { + auto pid = GetCurrentWorkerPId(); + if (pid) + { + return pid.GetPool()->GetIONetWorker(pid); + } + else + { + return {}; + } + } + + AuSPtr GetSelfIOGroup() + { + auto pid = GetCurrentWorkerPId(); + if (pid) + { + return pid.GetPool()->GetIOGroup(pid); + } + else + { + return {}; + } + } } \ No newline at end of file diff --git a/Source/Async/AsyncApp.cpp b/Source/Async/AsyncApp.cpp index 885b2757..9fd5b40c 100644 --- a/Source/Async/AsyncApp.cpp +++ b/Source/Async/AsyncApp.cpp @@ -248,6 +248,11 @@ namespace Aurora::Async return ThreadPool::GetIONetWorker(pid); } + AuSPtr AsyncApp::GetIOGroup(WorkerId_t pid) + { + return ThreadPool::GetIOGroup(pid); + } + AuSPtr AsyncApp::ToKernelWorkQueue() { return ThreadPool::ToKernelWorkQueue(); diff --git a/Source/Async/AsyncApp.hpp b/Source/Async/AsyncApp.hpp index 30c587ed..5aeaa835 100644 --- a/Source/Async/AsyncApp.hpp +++ b/Source/Async/AsyncApp.hpp @@ -48,6 +48,7 @@ namespace Aurora::Async AuSPtr GetIONetWorker(WorkerId_t pid) override; AuSPtr ToKernelWorkQueue() override; AuSPtr ToKernelWorkQueue(WorkerId_t workerId) override; + AuSPtr GetIOGroup(WorkerId_t id) override; // Main thread logic void Start() override; diff --git a/Source/Async/AuThreadStateSingletons.cpp b/Source/Async/AuThreadStateSingletons.cpp index f01c46d3..6950c6f1 100644 --- a/Source/Async/AuThreadStateSingletons.cpp +++ b/Source/Async/AuThreadStateSingletons.cpp @@ -29,6 +29,25 @@ namespace Aurora::Async } } + AuSPtr 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) diff --git a/Source/Async/AuThreadStateSingletons.hpp b/Source/Async/AuThreadStateSingletons.hpp index 3c085087..9ccbe20d 100644 --- a/Source/Async/AuThreadStateSingletons.hpp +++ b/Source/Async/AuThreadStateSingletons.hpp @@ -20,7 +20,9 @@ namespace Aurora::Async AuSPtr pIOProcessor; AuSPtr pNetInterface; AuSPtr pNetWorker; + AuSPtr pGroup; + AuSPtr GetIOGroup(); AuSPtr GetIOProcessor(AuWorkerPId_t pid); AuSPtr GetIONetInterface(AuWorkerPId_t pid); AuSPtr GetIONetWorker(AuWorkerPId_t pid); diff --git a/Source/Async/ThreadPool.cpp b/Source/Async/ThreadPool.cpp index 4f233278..edee1937 100644 --- a/Source/Async/ThreadPool.cpp +++ b/Source/Async/ThreadPool.cpp @@ -811,6 +811,16 @@ namespace Aurora::Async return {}; } + AuSPtr ThreadPool::GetIOGroup(WorkerId_t id) + { + if (auto pState = this->GetThreadHandle(id)) + { + return pState->singletons.GetIOGroup(); + } + + return {}; + } + AuSPtr ThreadPool::GetIONetInterface(WorkerId_t pid) { if (auto pState = this->GetThreadHandle(pid)) @@ -830,45 +840,6 @@ namespace Aurora::Async return {}; } - - AuSPtr ThreadPool::GetSelfIOProcessor() - { - auto pid = GetCurrentWorkerPId(); - if (pid) - { - return pid.GetPool()->GetIOProcessor(pid); - } - else - { - return {}; - } - } - - AuSPtr ThreadPool::GetSelfIONetInterface() - { - auto pid = GetCurrentWorkerPId(); - if (pid) - { - return pid.GetPool()->GetIONetInterface(pid); - } - else - { - return {}; - } - } - - AuSPtr ThreadPool::GetSelfIONetWorker() - { - auto pid = GetCurrentWorkerPId(); - if (pid) - { - return pid.GetPool()->GetIONetWorker(pid); - } - else - { - return {}; - } - } bool ThreadPool::Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal) { diff --git a/Source/Async/ThreadPool.hpp b/Source/Async/ThreadPool.hpp index e6bff9ac..4b3a3c26 100644 --- a/Source/Async/ThreadPool.hpp +++ b/Source/Async/ThreadPool.hpp @@ -63,10 +63,7 @@ namespace Aurora::Async virtual AuSPtr GetIOProcessor(WorkerId_t id) override; virtual AuSPtr GetIONetInterface(WorkerId_t pid) override; virtual AuSPtr GetIONetWorker(WorkerId_t id) override; - - AuSPtr GetSelfIOProcessor(); - AuSPtr GetSelfIONetInterface(); - AuSPtr GetSelfIONetWorker(); + virtual AuSPtr GetIOGroup(WorkerId_t id) override; virtual bool Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal) override; virtual void Signal(WorkerId_t workerId) override;