[*] Thread Group apis should be templates as well. This was refactor for async app not so long ago

This commit is contained in:
Reece Wilson 2021-11-07 22:32:33 +00:00
parent 22103a8ad3
commit 21f8b69a57
3 changed files with 39 additions and 55 deletions

View File

@ -37,6 +37,7 @@ namespace Aurora::Async
AUKN_SYM AuSPtr<IThreadPool> NewThreadPool();
// TODO: move the following trash out of here
// the following is mostly old trash
#pragma region EASE_OF_READING
struct BasicWorkStdFunc : IWorkItemHandler
{

View File

@ -12,65 +12,48 @@ namespace Aurora::Async
/// --- THREAD POOL --
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> NewWork(const WorkerPId_t &worker, const Task_t &task, const Job_t &job, bool enableWait = false)
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, class a = const Job_t &, class b = Task_t &>
static AuSPtr<IWorkItem> NewWork(const WorkerPId_t &worker, a task, b job, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(task, job), enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, class a = const Job_t &, class b = Task_t &>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, a task, b job, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(std::move(task), job), enableWait);
return NewWork<Info_t, Result_t, Task_t, Job_t>(worker, task, job, enableWait)->Dispatch();
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, const Task_t &task, const Job_t &job, bool enableWait = false)
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, class a, class b, class c>
static AuSPtr<IWorkItem> NewWork(const WorkerPId_t &worker, a task, b job, c info, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(task, job, info), enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, class a, class b, class c>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, a task, b job, c info, bool enableWait = false)
{
return NewWork<Info_t, Result_t, Task_t, Job_t>(worker, task, job, info, enableWait)->Dispatch();
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl, class a = const Job_t &, class b = const Info_t &>
AuSPtr<IWorkItem> DispatchFunctional(const WorkerPId_t &worker, ClazzImpl task, a job, b inputParameters, bool enableWait = false)
{
return NewWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, task, job, enableWait)->Dispatch();
return NewWork<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromConsumerRefT<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl, class a = const Job_t &, class b = const Info_t &>
AuSPtr<IWorkItem> DispatchFunctor(const WorkerPId_t &worker, ClazzImpl task, a job, b inputParameters, bool enableWait = false)
{
return NewWork<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromConsumerRefT<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl, class a = const Job_t &, class b = const Info_t &>
AuSPtr<IWorkItem> DispatchVoid(const WorkerPId_t &worker, ClazzImpl task, a job, b inputParameters, bool enableWait = false)
{
return NewWork<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromVoidVoid<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> NewWork(const WorkerPId_t &worker, Task_t &&task, const Job_t &job, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(std::move(task), job), enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, Task_t &&task, const Job_t &job, bool enableWait = false)
{
return NewWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, std::move(task), job, enableWait)->Dispatch();
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> NewWork(const WorkerPId_t &worker, Task_t &&task, Job_t &&job, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(std::move(task), std::move(job)), enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, Task_t &&task, Job_t &&job, bool enableWait = false)
{
return NewWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, std::move(task), std::move(job), enableWait)->Dispatch();
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
static AuSPtr<IWorkItem> DispatchWork(const WorkerPId_t &worker, const Task_t &task, const Job_t &job, const Info_t &inputParameters, bool enableWait = false)
{
return worker.pool->NewWorkItem(worker, AuMakeShared<WorkPairImpl<Info_t, Result_t, Task_t>>(task, job, inputParameters), enableWait)->Dispatch();
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl>
AuSPtr<IWorkItem> DispatchFunctional(const WorkerPId_t &worker, ClazzImpl task, const Job_t &job, const Info_t &inputParameters, bool enableWait = false)
{
return DispatchWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromConsumerRefT<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl>
AuSPtr<IWorkItem> DispatchFunctor(const WorkerPId_t &worker, ClazzImpl task, const Job_t &job, const Info_t &inputParameters, bool enableWait = false)
{
return DispatchWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromConsumerRefT<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>, typename ClazzImpl>
AuSPtr<IWorkItem> DispatchVoid(const WorkerPId_t &worker, ClazzImpl task, const Job_t &job, const Info_t &inputParameters, bool enableWait = false)
{
return DispatchWorkPairImpl<Info_t, Result_t, Task_t, Job_t>(worker, TaskFromVoidVoid<Info_t, Result_t>(task), job, inputParameters, enableWait);
}
/// --- ASYNC APP --

View File

@ -227,8 +227,8 @@ namespace Aurora::Async
private:
static constexpr bool IsCallbackPtr = std::is_pointer_v<Job_t> || AuIsBaseOfTemplate<std::shared_ptr, Job_t>::value;
static constexpr bool IsTaskPtr = std::is_pointer_v<Task_t> || AuIsBaseOfTemplate<std::shared_ptr, Task_t>::value;
static constexpr bool IsCallbackPtr = std::is_pointer_v<Job_t> || AuIsBaseOfTemplate<AuSPtr, Job_t>::value || AuIsBaseOfTemplate<AuUPtr, Job_t>::value;
static constexpr bool IsTaskPtr = std::is_pointer_v<Task_t> || AuIsBaseOfTemplate<AuSPtr, Task_t>::value || AuIsBaseOfTemplate<AuUPtr, Task_t>::value;
//WorkerId_t caller;
WorkerPId_t caller_;