diff --git a/Include/Aurora/Async/AsyncTypes.hpp b/Include/Aurora/Async/AsyncTypes.hpp index a13de0ec..a5e64eb3 100644 --- a/Include/Aurora/Async/AsyncTypes.hpp +++ b/Include/Aurora/Async/AsyncTypes.hpp @@ -14,6 +14,8 @@ namespace Aurora::IO::Loop namespace Aurora::Async { + AUKN_SYM WorkerPId_t GetCurrentWorkerPId(); + struct IWorkItem; struct IAsyncApp; struct IThreadPool; @@ -35,7 +37,9 @@ namespace Aurora::Async using ThreadId_t = AuUInt16; static const ThreadId_t kThreadIdAny = -1; - + + // NOTE: external library users can use the alias AuWorkerId_t + struct WorkerId_t : AuPair { inline WorkerId_t() : AuPair(0, 0) @@ -61,6 +65,9 @@ namespace Aurora::Async } }; + // NOTE: external library users can use the alias AuWorkerID + // NOTE: external library users can use the alias AuWorkerPId_t + struct WorkerPId_t : WorkerId_t { AU_COPY_MOVE_DEF(WorkerPId_t); @@ -86,7 +93,70 @@ namespace Aurora::Async inline WorkerPId_t(ThreadGroup_t group, ThreadId_t id) : WorkerId_t(group, id) { } - + + cstatic WorkerPId_t FromAnyInGroup(const AuSPtr &pool, + ThreadGroup_t group) + { + return WorkerPId_t(pool, group); + } + + cstatic WorkerPId_t FromJobRunner(const AuSPtr &pool, + ThreadGroup_t group, + ThreadId_t id) + { + return WorkerPId_t(pool, group, id); + } + + cstatic WorkerPId_t FromJobRunner(const AuSPtr &pool, + WorkerId_t id) + { + return WorkerPId_t(pool, id); + } + + cstatic WorkerPId_t FromThreadID(const AuSPtr &pool, + ThreadGroup_t group, + ThreadId_t id) + { + return FromJobRunner(pool, group, id); + } + + cstatic WorkerPId_t FromLocalAnyInGroup(ThreadGroup_t group) + { + auto worker = GetCurrentWorkerPId(); + SysAssertDbg(worker, "No attached to a thread pool"); + return FromJobRunner(worker.GetPool(), group); + } + + cstatic WorkerPId_t FromLocalJobRunner(ThreadGroup_t group, + ThreadId_t id) + { + auto worker = GetCurrentWorkerPId(); + SysAssertDbg(worker, "No attached to a thread pool"); + return FromJobRunner(worker.GetPool(), group, id); + } + + cstatic WorkerPId_t FromLocalJobRunner(WorkerId_t id) + { + auto worker = GetCurrentWorkerPId(); + SysAssertDbg(worker, "No attached to a thread pool"); + return FromJobRunner(worker.GetPool(), id); + } + + cstatic WorkerPId_t FromLocalThreadID(ThreadGroup_t group, + ThreadId_t id) + { + auto worker = GetCurrentWorkerPId(); + SysAssertDbg(worker, "No attached to a thread pool"); + return FromJobRunner(worker.GetPool(), group, id); + } + + cstatic WorkerPId_t FromLocalThreadID(ThreadId_t id) + { + auto worker = GetCurrentWorkerPId(); + SysAssertDbg(worker, "No in thread"); + return FromJobRunner(worker.GetPool(), worker.GetGroup(), id); + } + inline AuSPtr GetPool() const { return AuTryLockMemoryType(this->wpPool);