AuroraRuntime/Source/IO/IOSleep.NT.cpp
Reece Wilson 267c2216b0 [+] UDP over socket API via existing INetSrvDatagram layer
(...missing send)
[+] AuIO::Buffer::ViewReader
[+] AuIO::Buffer::ViewSeekableReadable
[+] AuIO::Buffer::ViewWriter
[*] Clean up AuCompression
[*[ AuLog messages must always crunch for memory
[*] Various bug fixes
[*] Refactor+clean up
2022-12-12 23:50:05 +00:00

66 lines
1.4 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOSleep.NT.hpp
Date: 2022-5-13
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IO.hpp"
#include "IOSleep.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;
}
}