[*] Retard proof AuWorkerID

This commit is contained in:
Reece Wilson 2024-02-25 23:07:24 +00:00
parent f68ac4a328
commit 7001a97870

View File

@ -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<ThreadGroup_t, ThreadId_t>
{
inline WorkerId_t() : AuPair<ThreadGroup_t, ThreadId_t>(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<IThreadPool> &pool,
ThreadGroup_t group)
{
return WorkerPId_t(pool, group);
}
cstatic WorkerPId_t FromJobRunner(const AuSPtr<IThreadPool> &pool,
ThreadGroup_t group,
ThreadId_t id)
{
return WorkerPId_t(pool, group, id);
}
cstatic WorkerPId_t FromJobRunner(const AuSPtr<IThreadPool> &pool,
WorkerId_t id)
{
return WorkerPId_t(pool, id);
}
cstatic WorkerPId_t FromThreadID(const AuSPtr<IThreadPool> &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<IThreadPool> GetPool() const
{
return AuTryLockMemoryType(this->wpPool);