AuroraRuntime/Source/IO/AuIOSleep.NT.cpp
Reece 4e6f116925 [*] Refactor
[+] IProcessSectionView::GetStart
[+] IProcessSectionView::GetEnd
2022-12-17 20:14:19 +00:00

66 lines
1.4 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOSleep.NT.hpp
Date: 2022-5-13
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IO.hpp"
#include "AuIOSleep.NT.hpp"
namespace Aurora::IO
{
AUKN_SYM bool WaitFor(AuUInt32 dwMilliseconds, bool bWaitEntireFrame)
{
bool bHit {};
AuUInt32 targetTime = dwMilliseconds ? AuTime::SteadyClockNS() + AuNSToMS<AuUInt64>(dwMilliseconds) : 0;
if (!dwMilliseconds)
{
bWaitEntireFrame = false;
}
while (true)
{
AuUInt32 dwSleep;
if (targetTime)
{
auto now = AuTime::SteadyClockNS();
if (now >= targetTime)
{
break;
}
dwSleep = AuNSToMS<AuUInt32>(now - targetTime);
}
else
{
dwSleep = INFINITE;
}
if (SleepEx(dwSleep, true) != WAIT_IO_COMPLETION)
{
continue;
}
while (SleepEx(0, true) == WAIT_IO_COMPLETION) ;
bHit = true;
if (!bWaitEntireFrame)
{
break;
}
}
return bHit;
}
AUKN_SYM bool IOYield()
{
return SleepEx(0, true) == WAIT_IO_COMPLETION;
}
}