AuroraRuntime/Source/Async/AuAsyncFuncWorker.cpp
Jamie Reece Wilson 8944d8bd16 [+] IAsyncTimer
[+] IAsyncTimerCallback
[+] ETickType.hpp
[+] EWorkPriority.hpp
[+] static IThreadPool::GetSelfIOProcessor()
[+] static IThreadPool::GetSelfIONetInterface()
[+] static IThreadPool::GetSelfIONetWorker()
[-] [Source/Async/]AsyncRunnable.hpp
[*] Begin encapsulating WorkerPId_t
[*] WorkerPId_t no longer take strong pointers to prevent leaks given that these identifiers are copied and kept alive everywhere
2023-12-07 09:20:23 +00:00

62 lines
1.5 KiB
C++

/***
Copyright (C) 2021-2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuAsyncFuncWorker.cpp
Date: 2023-12-06
Date: 2021-11-2
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IAsyncRunnable.hpp"
#include "AuAsyncFuncWorker.hpp"
#include "ThreadPool.hpp"
namespace Aurora::Async
{
AsyncFuncWorker::AsyncFuncWorker(IThreadPoolInternal *owner,
const WorkerPId_t &worker,
AuVoidFunc &&func) :
WorkItem(owner, worker, {}),
func(func)
{ }
void AsyncFuncWorker::DispatchTask(IWorkItemHandler::ProcessInfo &info)
{
auto func = AuExchange(this->func, {});
if (!this->CheckAlive())
{
return;
}
if (func)
{
func();
}
}
void AsyncFuncWorker::Cleanup()
{
AuResetMember(this->func);
}
AUKN_SYM AuSPtr<IWorkItem> NewWorkFunction(const WorkerPId_t &worker,
AuVoidFunc func)
{
AU_DEBUG_MEMCRUNCH;
if (!func)
{
SysPushErrorArg("WorkItem has null function");
return {};
}
auto pWorker = worker.GetPool();
if (!pWorker)
{
pWorker = GetCurrentWorkerPId().GetPool();
}
return AuMakeSharedThrow<AsyncFuncWorker>(AuStaticPointerCast<ThreadPool>(pWorker).get(), worker, AuMove(func));
}
}