Jamie Reece Wilson
a189151c59
[+] AuAsync::IThreadPool::GetIONetInterface [+] AuAsync::IThreadPool::GetIONetWorker [+] AuAsync::IWorkItem::SetSchedByLoopSource
109 lines
3.3 KiB
C++
109 lines
3.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: WorkItem.hpp
|
|
Date: 2021-6-26
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#include "ThreadPool.hpp"
|
|
|
|
namespace Aurora::Async
|
|
{
|
|
struct ThreadState;
|
|
|
|
struct WorkItem :
|
|
IWorkItem,
|
|
IAsyncRunnable,
|
|
AuEnableSharedFromThis<WorkItem>
|
|
{
|
|
WorkItem(IThreadPoolInternal *owner,
|
|
const WorkerPId_t &worker,
|
|
const AuSPtr<IWorkItemHandler> &task);
|
|
~WorkItem();
|
|
|
|
AuSPtr<IWorkItem> WaitFor(const AuSPtr<IWorkItem> &workItem) override;
|
|
AuSPtr<IWorkItem> WaitFor(const AuList<AuSPtr<IWorkItem>> &workItem) override;
|
|
AuSPtr<IWorkItem> SetSchedTime(AuUInt32 ms) override;
|
|
AuSPtr<IWorkItem> SetSchedTimeNs(AuUInt64 ns) override;
|
|
AuSPtr<IWorkItem> AddDelayTime(AuUInt32 ms) override;
|
|
AuSPtr<IWorkItem> AddDelayTimeNs(AuUInt64 ns) override;
|
|
AuSPtr<IWorkItem> SetSchedTimeAbs(AuUInt32 ms) override;
|
|
AuSPtr<IWorkItem> SetSchedTimeNsAbs(AuUInt64 ns) override;
|
|
AuSPtr<IWorkItem> SetSchedSteadyTimeNsAbs(AuUInt64 ns) override;
|
|
AuSPtr<IWorkItem> SetSchedByLoopSource(const AuSPtr<IO::Loop::ILoopSource> &pLoopSource) override;
|
|
AuSPtr<IWorkItem> Then(const AuSPtr<IWorkItem> &next) override;
|
|
|
|
AuSPtr<IWorkItem> Dispatch() override;
|
|
|
|
bool BlockUntilComplete() override;
|
|
bool HasFinished() override;
|
|
bool HasFailed() override;
|
|
|
|
void Cancel() override;
|
|
|
|
void RunAsync() override;
|
|
void CancelAsync() override;
|
|
|
|
|
|
void *GetPrivateData() override;
|
|
|
|
EWorkPrio GetPrio() override;
|
|
void SetPrio(EWorkPrio prio) override;
|
|
|
|
AuOptional<AuPair<AuUInt32, AuUInt32>> QueryFences();
|
|
|
|
protected:
|
|
bool CheckAlive();
|
|
|
|
private:
|
|
void RunAsyncLocked();
|
|
void RunAsyncLocked2();
|
|
void RunAsyncLocked2(const IWorkItemHandler::ProcessInfo &info);
|
|
bool WaitForLocked(const AuList<AuSPtr<IWorkItem>> &workItem);
|
|
|
|
void DispatchEx(bool check);
|
|
void DispatchExLocked(bool check);
|
|
|
|
virtual void DispatchTask(IWorkItemHandler::ProcessInfo &info);
|
|
|
|
IThreadPoolInternal *owner_ {};
|
|
AuSPtr<ThreadState> GetState();
|
|
|
|
AuSPtr<IWorkItemHandler> task_;
|
|
AuOptionalEx<WorkerPId_t> worker_;
|
|
EWorkPrio prio_ = EWorkPrio::eNormalPrio;
|
|
AuList<AuSPtr<IWorkItem>> waitOn_;
|
|
AuList<AuSPtr<IWorkItem>> waiters_;
|
|
AuThreadPrimitives::CriticalSection lock;
|
|
AuThreadPrimitives::CriticalSection lock2;
|
|
AuThreadPrimitives::Event finishedEvent_;
|
|
AuUInt32 uShutdownCookie {};
|
|
AuOptionalEx<AuUInt32> optOtherCookie {};
|
|
AuSPtr<AuIO::IIOProcessorItem> pIOWatch;
|
|
AuSPtr<IO::Loop::ILoopSource> pIOWatchLS;
|
|
|
|
bool finished {};
|
|
bool failed {};
|
|
bool dispatchPending_ {};
|
|
AuUInt64 dispatchTimeNs_ {};
|
|
AuUInt64 delayTimeNs_ {};
|
|
|
|
void Fail();
|
|
bool Schedule();
|
|
void SendOff();
|
|
};
|
|
|
|
struct FuncWorker : WorkItem
|
|
{
|
|
FuncWorker(IThreadPoolInternal *owner,
|
|
const WorkerPId_t &worker,
|
|
AuVoidFunc &&func);
|
|
|
|
void DispatchTask(IWorkItemHandler::ProcessInfo &info) override;
|
|
|
|
private:
|
|
AuVoidFunc func;
|
|
};
|
|
} |