68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
|
/***
|
||
|
Copyright (C) 2021-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||
|
|
||
|
File: LSTimerNoKernelScheduler.hpp
|
||
|
Date: 2024-09-08
|
||
|
Author: Reece
|
||
|
***/
|
||
|
#pragma once
|
||
|
|
||
|
#include "LSHandle.hpp"
|
||
|
#include "LSEvent.hpp"
|
||
|
|
||
|
namespace Aurora::IO::Loop
|
||
|
{
|
||
|
struct LSTimerIP;
|
||
|
|
||
|
struct LSTimerIPDispatcher : AuAsync::IAsyncRunnable
|
||
|
{
|
||
|
AuMutex mutex;
|
||
|
LSTimerIP *pParent {};
|
||
|
|
||
|
void RunAsync() override;
|
||
|
};
|
||
|
|
||
|
struct LSTimerIP : LSEvent, ITimer
|
||
|
{
|
||
|
LSTimerIP(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, bool bSingleshot);
|
||
|
~LSTimerIP();
|
||
|
|
||
|
PROXY_LOOP_LOOPSOURCE_EXT_WAIT_APIS_;
|
||
|
|
||
|
virtual void UpdateTimeWall(AuUInt64 absTimeMs) override;
|
||
|
virtual void UpdateTimeWallNs(AuUInt64 absTimeNs) override;
|
||
|
virtual void UpdateTimeSteady(AuUInt64 absTimeMs) override;
|
||
|
virtual void UpdateTimeSteadyNs(AuUInt64 absTimeNs) override;
|
||
|
virtual void UpdateTickRateIfAny(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero) override;
|
||
|
virtual void UpdateTickRateIfAnyNs(AuUInt64 reschedStepNsOrZero, AuUInt32 maxIterationsOrZero) override;
|
||
|
virtual void Stop() override;
|
||
|
|
||
|
bool TryInit();
|
||
|
|
||
|
bool IsSignaled() override;
|
||
|
bool IsSignaledNoSpinIfUserland() override;
|
||
|
ELoopSource GetType() override;
|
||
|
|
||
|
virtual bool OnTrigger(AuUInt handle) override;
|
||
|
|
||
|
bool TryTakeNoSpin();
|
||
|
bool TryTakeSpin();
|
||
|
bool TryTake();
|
||
|
bool TryTakeWaitNS(AuUInt64 timeout);
|
||
|
|
||
|
void UpdateTimeInternal(AuUInt64 absTimeMs);
|
||
|
void UpdateTimeInternalSteady(AuUInt64 absTimeMs);
|
||
|
|
||
|
private:
|
||
|
friend struct LSTimerIPDispatcher;
|
||
|
AuUInt32 maxIterationsOrZero_ {};
|
||
|
AuUInt64 reschedStepNsOrZero_ {}, targetTime_ {};
|
||
|
AuUInt32 count_ {};
|
||
|
bool bSingleshot {};
|
||
|
|
||
|
AuCriticalSection cs;
|
||
|
AuMutex dispatcherMutex;
|
||
|
AuSPtr<LSTimerIPDispatcher> pDispatcher;
|
||
|
bool IsSignaledNonblocking();
|
||
|
};
|
||
|
}
|