AuroraRuntime/Source/Async/AuAsyncTimer.hpp

42 lines
1.1 KiB
C++

/***
Copyright (C) 2021-2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuAsyncTimer.hpp
Date: 2023-12-06
Author: Reece
***/
#pragma once
#include "WorkItem.hpp"
namespace Aurora::Async
{
struct AsyncFuncTimer :
WorkItem,
IAsyncTimer
{
AsyncFuncTimer(IThreadPoolInternal *owner,
const AuSPtr<IAsyncTimerCallback> &pCallback,
const WorkerPId_t &worker,
AuUInt64 uNextTickTime,
AuUInt64 uInterval);
void CancelTimer() override;
AuUInt64 GetLastTime() override;
AuUInt64 GetTicks() override;
bool IsCatchUp() override;
void SetCatchUp(bool bCatchUp) override;
void DispatchTask(IWorkItemHandler::ProcessInfo &info) override;
void Cleanup() override;
private:
AuSPtr<IAsyncTimerCallback> pCallback;
WorkerPId_t worker;
AuUInt64 uNextTickTime {};
AuUInt64 uLastTickTime {};
AuUInt64 uInterval {};
AuUInt64 uTickCount {};
bool bCatchUp { false };
AuCriticalSection mutex;
};
}