From addd4080b268bbc0008e077914f36dbfaa600001 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 15 Sep 2023 16:41:10 +0100 Subject: [PATCH] [*] Adjust PId_t::pool null behaviour --- Include/Aurora/Async/Async.hpp | 3 --- Include/Aurora/Async/AsyncTypes.hpp | 8 +++---- Include/Aurora/Async/AuFutures.hpp | 6 ++--- Source/Async/WorkItem.cpp | 35 ++++++++--------------------- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/Include/Aurora/Async/Async.hpp b/Include/Aurora/Async/Async.hpp index b2b51bb7..18644cd4 100644 --- a/Include/Aurora/Async/Async.hpp +++ b/Include/Aurora/Async/Async.hpp @@ -25,7 +25,6 @@ namespace Aurora::Async /// AUKN_SYM WorkerPId_t GetCurrentWorkerPId(); - /// Async app only | Thread pools must use the IThreadPool::NewFence function AUKN_SYM AuSPtr NewWorkItem(const WorkerId_t &worker, const AuSPtr &task); /** @@ -47,9 +46,7 @@ namespace Aurora::Async /// Async app only | Thread pools must use the IThreadPool::NewFence function AUKN_SYM AuSPtr NewFence(); - /// Allocates a new thread pool for usage AUKN_SYM AuSPtr NewThreadPool(); - /// AUKN_SYM void SetMainThreadForSysPumpScheduling(WorkerPId_t pid); } diff --git a/Include/Aurora/Async/AsyncTypes.hpp b/Include/Aurora/Async/AsyncTypes.hpp index 059a27e0..2d90a22e 100644 --- a/Include/Aurora/Async/AsyncTypes.hpp +++ b/Include/Aurora/Async/AsyncTypes.hpp @@ -79,6 +79,9 @@ namespace Aurora::Async inline WorkerPId_t(const AuSPtr &pool, const WorkerId_t &cpy) : WorkerId_t(cpy.first, cpy.second), pool(pool) {} + + inline WorkerPId_t(ThreadGroup_t group, ThreadId_t id) : WorkerId_t(group, id) + { } AuSPtr pool; @@ -91,10 +94,5 @@ namespace Aurora::Async { return in.pool == this->pool && in.first == this->first && this->second == in.second; } - - inline operator bool() const - { - return pool; - } }; } \ No newline at end of file diff --git a/Include/Aurora/Async/AuFutures.hpp b/Include/Aurora/Async/AuFutures.hpp index 5f6bb5dd..825570fe 100644 --- a/Include/Aurora/Async/AuFutures.hpp +++ b/Include/Aurora/Async/AuFutures.hpp @@ -71,7 +71,7 @@ public: } else { - SysAssert(this->pid == AuAsync::GetCurrentWorkerPId()); + SysAssert(this->pid.value() == AuAsync::GetCurrentWorkerPId()); } } @@ -103,7 +103,7 @@ public: } else { - SysAssert(this->pid == AuAsync::GetCurrentWorkerPId()); + SysAssert(this->pid.value() == AuAsync::GetCurrentWorkerPId()); } this->onFailure = onFailure; @@ -216,7 +216,7 @@ private: void SubmitComplete() { - if (AuAsync::GetCurrentWorkerPId() == this->pid) + if (AuAsync::GetCurrentWorkerPId() == this->pid.value()) { if (!this->onFailure && !this->callback) { diff --git a/Source/Async/WorkItem.cpp b/Source/Async/WorkItem.cpp index c4d559e2..5d574ec1 100644 --- a/Source/Async/WorkItem.cpp +++ b/Source/Async/WorkItem.cpp @@ -453,18 +453,9 @@ namespace Aurora::Async this->owner_->Run(this->worker_, AuSharedFromThis()); } } - static auto GetWorkerInternal() - { - return static_cast(GetAsyncApp()); - } - inline auto GetWorkerInternal(const AuSPtr &pool) + inline auto ToInternal(const AuSPtr &pool) { - if (pool.get() == AuStaticCast(gAsyncApp)) - { - return AuUnsafeRaiiToShared(AuStaticCast(gAsyncApp)); - } - return AuStaticPointerCast(pool); } @@ -486,7 +477,9 @@ namespace Aurora::Async return {}; } - return AuMakeShared(GetWorkerInternal(), WorkerPId_t { AuAsync::GetCurrentWorkerPId().pool, worker }, task); + auto pWorker = GetCurrentWorkerPId().pool; + if (!pWorker) AuUnsafeRaiiToShared(gAsyncApp); + return AuMakeShared(ToInternal(pWorker).get(), WorkerPId_t { pWorker , worker }, task); } AUKN_SYM AuSPtr NewWorkFunction(const WorkerPId_t &worker, AuVoidFunc func) @@ -499,13 +492,7 @@ namespace Aurora::Async return {}; } - if (!worker) - { - SysPushErrorArg("invalid worker"); - return {}; - } - - return AuMakeSharedThrow(GetWorkerInternal(worker.pool).get(), worker, AuMove(func)); + return AuMakeSharedThrow(ToInternal(worker.pool).get(), worker, AuMove(func)); } AUKN_SYM AuSPtr NewWorkItem(const WorkerPId_t &worker, const AuSPtr &task) @@ -518,18 +505,14 @@ namespace Aurora::Async return {}; } - if (!worker) - { - SysPushErrorArg("invalid worker"); - return {}; - } - - return AuMakeSharedThrow(GetWorkerInternal(worker.pool).get(), worker, task); + return AuMakeSharedThrow(ToInternal(worker.pool).get(), worker, task); } AUKN_SYM AuSPtr NewFence() { - return AuMakeShared(GetWorkerInternal(), AuAsync::GetCurrentWorkerPId(), AuSPtr{}); + auto pWorker = GetCurrentWorkerPId().pool; + if (!pWorker) AuUnsafeRaiiToShared(gAsyncApp); + return AuMakeShared((IThreadPoolInternal *)ToInternal(pWorker).get(), WorkerPId_t {}, AuSPtr{}); } void *WorkItem::GetPrivateData()