[*] AuAsync: remove illegal static casts
This commit is contained in:
parent
00c82fdbe4
commit
de504a3a2d
@ -15,7 +15,6 @@
|
||||
|
||||
namespace Aurora::Async
|
||||
{
|
||||
static AsyncApp *gAsyncApp;
|
||||
static AuSPtr<AsyncApp> gAsyncAppMem;
|
||||
|
||||
void InitApp()
|
||||
|
@ -13,6 +13,8 @@ namespace Aurora::Async
|
||||
{
|
||||
void InitApp();
|
||||
void ReleaseApp();
|
||||
|
||||
inline struct AsyncApp *gAsyncApp;
|
||||
|
||||
struct AsyncApp : public IAsyncApp, ThreadPool
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ namespace Aurora::Async
|
||||
if (entry.pool->ToThreadPool()->InRunnerMode())
|
||||
{
|
||||
AuLogWarn("Dropped scheduled task! Expect a leaky counter!");
|
||||
AuLogWarn("Would you rather `Why u no exit?!` or `WHY DID U JUST CRASH REEEE` in production?");
|
||||
AuLogWarn("Would you rather `Why u no exit?!` or a spurious crash in production?");
|
||||
}
|
||||
Debug::PrintError();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "Async.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
#include "AsyncApp.hpp"
|
||||
#include "WorkItem.hpp"
|
||||
#include "Schedular.hpp"
|
||||
#include "ThreadWorkerQueueShim.hpp"
|
||||
@ -18,6 +19,16 @@ namespace Aurora::Async
|
||||
static thread_local AuWPtr<ThreadPool> gCurrentPool;
|
||||
static const auto kMagicResortThreshold = 15;
|
||||
|
||||
inline auto GetWorkerInternal(const AuSPtr<IThreadPool> &pool)
|
||||
{
|
||||
if (pool.get() == AuStaticCast<IAsyncApp>(gAsyncApp))
|
||||
{
|
||||
return AuUnsafeRaiiToShared(AuStaticCast<ThreadPool>(gAsyncApp));
|
||||
}
|
||||
|
||||
return AuStaticPointerCast<ThreadPool>(pool);
|
||||
}
|
||||
|
||||
AUKN_SYM WorkerPId_t GetCurrentWorkerPId()
|
||||
{
|
||||
auto lkPool = gCurrentPool.lock();
|
||||
@ -939,7 +950,7 @@ namespace Aurora::Async
|
||||
auto pid = GetCurrentWorkerPId();
|
||||
if (pid.pool)
|
||||
{
|
||||
AuStaticPointerCast<ThreadPool>(pid.pool)->ThisExiting();
|
||||
GetWorkerInternal(pid.pool)->ThisExiting();
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -222,9 +222,15 @@ namespace Aurora::Async
|
||||
Fail();
|
||||
}
|
||||
|
||||
|
||||
void WorkItem::RunAsync()
|
||||
{
|
||||
AU_LOCK_GUARD(this->lock);
|
||||
RunAsyncLocked();
|
||||
}
|
||||
|
||||
void WorkItem::RunAsyncLocked()
|
||||
{
|
||||
|
||||
IWorkItemHandler::ProcessInfo info(true);
|
||||
info.pool = this->owner_->ToThreadPool();
|
||||
@ -238,6 +244,7 @@ namespace Aurora::Async
|
||||
{
|
||||
case ETickType::eFinished:
|
||||
{
|
||||
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
@ -343,7 +350,7 @@ namespace Aurora::Async
|
||||
|
||||
void WorkItem::Schedule()
|
||||
{
|
||||
Async::Schedule(this->dispatchTimeNs_, this->owner_, this->worker_, this->shared_from_this());
|
||||
Async::Schedule(this->dispatchTimeNs_, this->owner_, this->worker_, AuSharedFromThis());
|
||||
}
|
||||
|
||||
void WorkItem::SendOff()
|
||||
@ -351,24 +358,28 @@ namespace Aurora::Async
|
||||
if (!this->task_)
|
||||
{
|
||||
// If we aren't actually calling a task interface, we may as well just dispatch objects waiting on us from here
|
||||
RunAsync();
|
||||
RunAsyncLocked();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->owner_->Run(this->worker_, this->shared_from_this());
|
||||
this->owner_->Run(this->worker_, AuSharedFromThis());
|
||||
}
|
||||
}
|
||||
|
||||
static auto GetWorkerInternal(const AuSPtr<IThreadPool> &pool)
|
||||
{
|
||||
return AuStaticPointerCast<ThreadPool>(pool).get();
|
||||
}
|
||||
|
||||
static auto GetWorkerInternal()
|
||||
{
|
||||
return static_cast<AsyncApp *>(GetAsyncApp());
|
||||
}
|
||||
|
||||
inline auto GetWorkerInternal(const AuSPtr<IThreadPool> &pool)
|
||||
{
|
||||
if (pool.get() == AuStaticCast<IAsyncApp>(gAsyncApp))
|
||||
{
|
||||
return AuUnsafeRaiiToShared(AuStaticCast<ThreadPool>(gAsyncApp));
|
||||
}
|
||||
|
||||
return AuStaticPointerCast<ThreadPool>(pool);
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IWorkItem> NewWorkItem(const WorkerId_t &worker, const AuSPtr<IWorkItemHandler> &task, bool supportsBlocking)
|
||||
{
|
||||
if (!task)
|
||||
@ -390,8 +401,8 @@ namespace Aurora::Async
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return AuMakeShared<WorkItem>(AuStaticCast<ThreadPool>(worker.pool).get(), worker, task, supportsBlocking);
|
||||
|
||||
return AuMakeShared<WorkItem>(GetWorkerInternal(worker.pool).get(), worker, task, supportsBlocking);
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IWorkItem> NewFence()
|
||||
|
@ -46,6 +46,7 @@ namespace Aurora::Async
|
||||
void SetPrio(float val) override;
|
||||
|
||||
private:
|
||||
void RunAsyncLocked();
|
||||
|
||||
bool WaitForLocked(const AuList<AuSPtr<IWorkItem>> &workItem);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user