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