Reece
7eb6900e9f
[+] AuRemoveConst [*] Support circular reference in Aurora pipelines Include, added support for early Aurora::Build AuroraEnum [+] Added SWInfo API [+] AU_COPY_MOVE, AU_MOVE, AU_COPY to go with AU_NO_... variants [+] Adding GetProcessId
69 lines
2.1 KiB
C++
69 lines
2.1 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
|
|
{
|
|
class WorkItem : public IWorkItem, public IAsyncRunnable, public AuEnableSharedFromThis<WorkItem>
|
|
{
|
|
public:
|
|
WorkItem(IThreadPoolInternal *owner, const WorkerId_t &worker_, const AuSPtr<IWorkItemHandler> &task_, bool supportsBlocking);
|
|
~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> 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;
|
|
AuOptional<void *> ToWorkResultT() override;
|
|
|
|
float GetPrio() override;
|
|
void SetPrio(float val) override;
|
|
|
|
private:
|
|
void DispatchEx(bool check);
|
|
AuSPtr<IWorkItemHandler> task_;
|
|
WorkerId_t worker_;
|
|
float prio_ = 0.5f;
|
|
AuList<AuSPtr<IWorkItem>> waitOn_;
|
|
AuList<AuSPtr<IWorkItem>> waiters_;
|
|
AuThreadPrimitives::SpinLock lock;
|
|
AuThreadPrimitives::EventUnique_t finishedEvent_;
|
|
|
|
bool finished {};
|
|
bool failed {};
|
|
bool dispatchPending_ {};
|
|
AuUInt64 dispatchTimeNs_ {};
|
|
AuUInt64 delayTimeNs_ {};
|
|
IThreadPoolInternal *owner_ {};
|
|
|
|
void Fail();
|
|
void Schedule();
|
|
void SendOff();
|
|
};
|
|
} |