/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: IOSleep.NT.hpp Date: 2022-5-13 Author: Reece ***/ #include #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(dwMilliseconds) : 0; if (!dwMilliseconds) { bWaitEntireFrame = false; } while (true) { AuUInt32 dwSleep; if (targetTime) { auto now = AuTime::SteadyClockNS(); if (now >= targetTime) { break; } dwSleep = AuNSToMS(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; } }