[+] Add singleshot timer API flag
This commit is contained in:
parent
9f93b8a0b1
commit
2af66e0f71
@ -56,7 +56,7 @@ namespace Aurora::Loop
|
||||
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Threading::IWaitable> &primitive);
|
||||
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<ILSMutex> &source);
|
||||
|
||||
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absStartTimeMs /*CurrentClockMS()*/, AuUInt32 reschedStepMsOrZero = 0, AuUInt32 maxIterationsOrZero = 0);
|
||||
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absStartTimeMs /*CurrentClockMS()*/, AuUInt32 reschedStepMsOrZero = 0, AuUInt32 maxIterationsOrZero = 0, bool bSingleshot = false /*cannot be changed*/);
|
||||
AUKN_SYM AuSPtr<ILSMutex> NewLSMutex();
|
||||
AUKN_SYM AuSPtr<ILSEvent> NewLSEvent(bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false);
|
||||
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount = 0);
|
||||
|
@ -13,7 +13,7 @@ namespace Aurora::Loop
|
||||
{
|
||||
struct LSTimer : ITimer, LSHandle
|
||||
{
|
||||
LSTimer(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, HANDLE handle);
|
||||
LSTimer(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, bool bSingleshot, HANDLE handle);
|
||||
~LSTimer();
|
||||
|
||||
virtual void UpdateTime(AuUInt64 absTimeMs) override;
|
||||
@ -35,11 +35,13 @@ namespace Aurora::Loop
|
||||
AuUInt32 maxIterationsOrZero_ {0};
|
||||
AuUInt64 targetTime_ {0};
|
||||
AuUInt32 count_ {0};
|
||||
bool bSingleshot {};
|
||||
};
|
||||
|
||||
LSTimer::LSTimer(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, HANDLE handle) :
|
||||
LSTimer::LSTimer(AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, bool bSingleshot, HANDLE handle) :
|
||||
LSHandle(AuReinterpretCast<AuUInt>(handle)),
|
||||
reschedStepNsOrZero_(AuMSToNS<AuUInt64>(reschedStepMsOrZero)),
|
||||
bSingleshot(bSingleshot),
|
||||
maxIterationsOrZero_(maxIterationsOrZero)
|
||||
{
|
||||
this->targetTime_ = AuTime::ConvertTimestamp(AuTime::CurrentClockMS());
|
||||
@ -89,6 +91,7 @@ namespace Aurora::Loop
|
||||
bool LSTimer::OnTrigger(AuUInt handle)
|
||||
{
|
||||
SysAssert(this->targetTime_ <= AuTime::ConvertTimestampNs(AuTime::CurrentClockNS()));
|
||||
|
||||
if (!this->reschedStepNsOrZero_)
|
||||
{
|
||||
return true;
|
||||
@ -137,19 +140,19 @@ namespace Aurora::Loop
|
||||
return ELoopSource::eSourceTimer;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absStartTimeMs, AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero)
|
||||
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absStartTimeMs, AuUInt32 reschedStepMsOrZero, AuUInt32 maxIterationsOrZero, bool bSingleshot)
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolwait
|
||||
// TODO: Is that any better with an event?
|
||||
|
||||
auto handle = CreateWaitableTimerW(nullptr, true, nullptr);
|
||||
auto handle = CreateWaitableTimerW(nullptr, !bSingleshot, nullptr);
|
||||
if (!handle)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto object = AuMakeShared<LSTimer>(reschedStepMsOrZero, maxIterationsOrZero, handle);
|
||||
auto object = AuMakeShared<LSTimer>(reschedStepMsOrZero, maxIterationsOrZero, bSingleshot, handle);
|
||||
if (!object)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
@ -157,7 +160,10 @@ namespace Aurora::Loop
|
||||
return {};
|
||||
}
|
||||
|
||||
object->UpdateTime(absStartTimeMs);
|
||||
if (absStartTimeMs)
|
||||
{
|
||||
object->UpdateTime(absStartTimeMs);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user