[+] Added AuAsync per thread io group singleton

[*] Move static functions out of the thread pool interface. no idea how i had successful builds before
This commit is contained in:
Reece Wilson 2024-07-12 17:22:07 +01:00
parent 2b2f5c3d23
commit d803f1547c
10 changed files with 114 additions and 47 deletions

View File

@ -61,6 +61,11 @@ namespace Aurora::Async
AUKN_SYM AuSPtr<IThreadPool> NewThreadPool(); AUKN_SYM AuSPtr<IThreadPool> NewThreadPool();
AUKN_SYM void SetMainThreadForSysPumpScheduling(WorkerPId_t pid); AUKN_SYM void SetMainThreadForSysPumpScheduling(WorkerPId_t pid);
AUKN_SYM AuSPtr<IO::IIOProcessor> GetSelfIOProcessor();
AUKN_SYM AuSPtr<IO::Net::INetInterface> GetSelfIONetInterface();
AUKN_SYM AuSPtr<IO::Net::INetWorker> GetSelfIONetWorker();
AUKN_SYM AuSPtr<IO::CompletionGroup::ICompletionGroup> GetSelfIOGroup();
} }
#if !defined(_CPPSHARP) #if !defined(_CPPSHARP)

View File

@ -19,6 +19,11 @@ namespace Aurora::IO::Net
struct INetWorker; struct INetWorker;
} }
namespace Aurora::IO::CompletionGroup
{
struct ICompletionGroup;
}
namespace Aurora::Async namespace Aurora::Async
{ {
struct IThreadPool struct IThreadPool
@ -87,10 +92,7 @@ namespace Aurora::Async
virtual AuSPtr<IO::IIOProcessor> GetIOProcessor(WorkerId_t id) = 0; virtual AuSPtr<IO::IIOProcessor> GetIOProcessor(WorkerId_t id) = 0;
virtual AuSPtr<IO::Net::INetInterface> GetIONetInterface(WorkerId_t id) = 0; virtual AuSPtr<IO::Net::INetInterface> GetIONetInterface(WorkerId_t id) = 0;
virtual AuSPtr<IO::Net::INetWorker> GetIONetWorker(WorkerId_t id) = 0; virtual AuSPtr<IO::Net::INetWorker> GetIONetWorker(WorkerId_t id) = 0;
virtual AuSPtr<IO::CompletionGroup::ICompletionGroup> GetIOGroup(WorkerId_t id) = 0;
static AuSPtr<IO::IIOProcessor> GetSelfIOProcessor();
static AuSPtr<IO::Net::INetInterface> GetSelfIONetInterface();
static AuSPtr<IO::Net::INetWorker> GetSelfIONetWorker();
// Synchronization // Synchronization

View File

@ -17,6 +17,11 @@ namespace Aurora::IO::CompletionGroup
struct ICompletionGroup; struct ICompletionGroup;
} }
namespace Aurora::Async
{
AUKN_SYM AuSPtr<IO::CompletionGroup::ICompletionGroup> GetSelfIOGroup();
}
#include "CompletionGroup/ICompletionGroupWorkHandle.hpp" #include "CompletionGroup/ICompletionGroupWorkHandle.hpp"
#include <Aurora/Debug/Debug.hpp> #include <Aurora/Debug/Debug.hpp>
@ -132,6 +137,10 @@ namespace Aurora::IO
{ {
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
} }
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback) if (callback)
{ {
@ -157,6 +166,10 @@ namespace Aurora::IO
{ {
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
} }
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback) if (callback)
{ {

View File

@ -23,4 +23,56 @@ namespace Aurora::Async
DeinitSched(); DeinitSched();
ReleaseApp(); ReleaseApp();
} }
AuSPtr<IO::IIOProcessor> GetSelfIOProcessor()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIOProcessor(pid);
}
else
{
return {};
}
}
AuSPtr<IO::Net::INetInterface> GetSelfIONetInterface()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIONetInterface(pid);
}
else
{
return {};
}
}
AuSPtr<IO::Net::INetWorker> GetSelfIONetWorker()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIONetWorker(pid);
}
else
{
return {};
}
}
AuSPtr<IO::CompletionGroup::ICompletionGroup> GetSelfIOGroup()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIOGroup(pid);
}
else
{
return {};
}
}
} }

View File

@ -248,6 +248,11 @@ namespace Aurora::Async
return ThreadPool::GetIONetWorker(pid); return ThreadPool::GetIONetWorker(pid);
} }
AuSPtr<IO::CompletionGroup::ICompletionGroup> AsyncApp::GetIOGroup(WorkerId_t pid)
{
return ThreadPool::GetIOGroup(pid);
}
AuSPtr<AuLoop::ILoopQueue> AsyncApp::ToKernelWorkQueue() AuSPtr<AuLoop::ILoopQueue> AsyncApp::ToKernelWorkQueue()
{ {
return ThreadPool::ToKernelWorkQueue(); return ThreadPool::ToKernelWorkQueue();

View File

@ -48,6 +48,7 @@ namespace Aurora::Async
AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(WorkerId_t pid) override; AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(WorkerId_t pid) override;
AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue() override; AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue() override;
AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue(WorkerId_t workerId) override; AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue(WorkerId_t workerId) override;
AuSPtr<IO::CompletionGroup::ICompletionGroup> GetIOGroup(WorkerId_t id) override;
// Main thread logic // Main thread logic
void Start() override; void Start() override;

View File

@ -29,6 +29,25 @@ namespace Aurora::Async
} }
} }
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) void ThreadStateSingletons::TryInitNet(AuWorkerPId_t pid)
{ {
if (this->pNetInterface) if (this->pNetInterface)

View File

@ -20,7 +20,9 @@ namespace Aurora::Async
AuSPtr<AuIO::IIOProcessor> pIOProcessor; AuSPtr<AuIO::IIOProcessor> pIOProcessor;
AuSPtr<AuIO::Net::INetInterface> pNetInterface; AuSPtr<AuIO::Net::INetInterface> pNetInterface;
AuSPtr<AuIO::Net::INetWorker> pNetWorker; AuSPtr<AuIO::Net::INetWorker> pNetWorker;
AuSPtr<AuIO::CompletionGroup::ICompletionGroup> pGroup;
AuSPtr<AuIO::CompletionGroup::ICompletionGroup> GetIOGroup();
AuSPtr<AuIO::IIOProcessor> GetIOProcessor(AuWorkerPId_t pid); AuSPtr<AuIO::IIOProcessor> GetIOProcessor(AuWorkerPId_t pid);
AuSPtr<AuIO::Net::INetInterface> GetIONetInterface(AuWorkerPId_t pid); AuSPtr<AuIO::Net::INetInterface> GetIONetInterface(AuWorkerPId_t pid);
AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(AuWorkerPId_t pid); AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(AuWorkerPId_t pid);

View File

@ -811,6 +811,16 @@ namespace Aurora::Async
return {}; return {};
} }
AuSPtr<IO::CompletionGroup::ICompletionGroup> ThreadPool::GetIOGroup(WorkerId_t id)
{
if (auto pState = this->GetThreadHandle(id))
{
return pState->singletons.GetIOGroup();
}
return {};
}
AuSPtr<AuIO::Net::INetInterface> ThreadPool::GetIONetInterface(WorkerId_t pid) AuSPtr<AuIO::Net::INetInterface> ThreadPool::GetIONetInterface(WorkerId_t pid)
{ {
if (auto pState = this->GetThreadHandle(pid)) if (auto pState = this->GetThreadHandle(pid))
@ -831,45 +841,6 @@ namespace Aurora::Async
return {}; return {};
} }
AuSPtr<IO::IIOProcessor> ThreadPool::GetSelfIOProcessor()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIOProcessor(pid);
}
else
{
return {};
}
}
AuSPtr<IO::Net::INetInterface> ThreadPool::GetSelfIONetInterface()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIONetInterface(pid);
}
else
{
return {};
}
}
AuSPtr<IO::Net::INetWorker> ThreadPool::GetSelfIONetWorker()
{
auto pid = GetCurrentWorkerPId();
if (pid)
{
return pid.GetPool()->GetIONetWorker(pid);
}
else
{
return {};
}
}
bool ThreadPool::Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal) bool ThreadPool::Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal)
{ {
AU_LOCK_GUARD(this->pRWReadView); AU_LOCK_GUARD(this->pRWReadView);

View File

@ -63,10 +63,7 @@ namespace Aurora::Async
virtual AuSPtr<AuIO::IIOProcessor> GetIOProcessor(WorkerId_t id) override; virtual AuSPtr<AuIO::IIOProcessor> GetIOProcessor(WorkerId_t id) override;
virtual AuSPtr<AuIO::Net::INetInterface> GetIONetInterface(WorkerId_t pid) override; virtual AuSPtr<AuIO::Net::INetInterface> GetIONetInterface(WorkerId_t pid) override;
virtual AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(WorkerId_t id) override; virtual AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(WorkerId_t id) override;
virtual AuSPtr<AuIO::CompletionGroup::ICompletionGroup> GetIOGroup(WorkerId_t id) override;
AuSPtr<IO::IIOProcessor> GetSelfIOProcessor();
AuSPtr<IO::Net::INetInterface> GetSelfIONetInterface();
AuSPtr<IO::Net::INetWorker> GetSelfIONetWorker();
virtual bool Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal) override; virtual bool Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal) override;
virtual void Signal(WorkerId_t workerId) override; virtual void Signal(WorkerId_t workerId) override;