This commit is contained in:
Reece Wilson 2023-09-15 16:53:18 +01:00
parent f1e9aa1d22
commit d49d4ad4fc

View File

@ -478,7 +478,11 @@ namespace Aurora::Async
}
auto pWorker = GetCurrentWorkerPId().pool;
if (!pWorker) AuUnsafeRaiiToShared(gAsyncApp);
if (!pWorker)
{
pWorker = AuUnsafeRaiiToShared(gAsyncApp);
}
return AuMakeShared<WorkItem>(ToInternal(pWorker).get(), WorkerPId_t { pWorker , worker }, task);
}
@ -492,7 +496,18 @@ namespace Aurora::Async
return {};
}
return AuMakeSharedThrow<FuncWorker>(ToInternal(worker.pool).get(), worker, AuMove(func));
auto pWorker = worker.pool;
if (!pWorker)
{
pWorker = GetCurrentWorkerPId().pool;
}
if (!pWorker)
{
pWorker = AuUnsafeRaiiToShared(gAsyncApp);
}
return AuMakeSharedThrow<FuncWorker>(ToInternal(pWorker).get(), worker, AuMove(func));
}
AUKN_SYM AuSPtr<IWorkItem> NewWorkItem(const WorkerPId_t &worker, const AuSPtr<IWorkItemHandler> &task)
@ -505,13 +520,27 @@ namespace Aurora::Async
return {};
}
return AuMakeSharedThrow<WorkItem>(ToInternal(worker.pool).get(), worker, task);
auto pWorker = worker.pool;
if (!pWorker)
{
pWorker = GetCurrentWorkerPId().pool;
}
if (!pWorker)
{
pWorker = AuUnsafeRaiiToShared(gAsyncApp);
}
return AuMakeSharedThrow<WorkItem>(ToInternal(pWorker).get(), worker, task);
}
AUKN_SYM AuSPtr<IWorkItem> NewFence()
{
auto pWorker = GetCurrentWorkerPId().pool;
if (!pWorker) AuUnsafeRaiiToShared(gAsyncApp);
if (!pWorker)
{
pWorker = AuUnsafeRaiiToShared(gAsyncApp);
}
return AuMakeShared<WorkItem>((IThreadPoolInternal *)ToInternal(pWorker).get(), WorkerPId_t {}, AuSPtr<IWorkItemHandler>{});
}