AuroraRuntime/Source/IO/Loop/LSWin32.NT.cpp

96 lines
2.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSWin32.NT.cpp
Date: 2021-10-2
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "LSWin32.NT.hpp"
#if !defined(PM_NOREMOVE)
#define PM_NOREMOVE 0x0000
#endif
namespace Aurora::IO::Loop
{
bool Win32Dummy::IsSignaled()
{
MSG askers;
return pPeekMessageW &&
pPeekMessageW(&askers, 0, 0, 0, PM_NOREMOVE);
}
bool Win32Dummy::IsSignaledExt(AuUInt8 uFlags)
{
return this->IsSignaled();
}
bool Win32Dummy::WaitOn(AuUInt32 timeout)
{
// TODO: Close
static HANDLE kAlwaysOffMutex = CreateEventW(nullptr, true, false, nullptr);
if (!pMsgWaitForMultipleObjects)
{
return false;
}
#if defined(QS_ALLEVENTS)
return pMsgWaitForMultipleObjects(0, &kAlwaysOffMutex, false, timeout ? timeout : INFINITE, QS_ALLEVENTS) == WAIT_OBJECT_0 + 1;
#else
return false;
#endif
}
ELoopSource Win32Dummy::GetType()
{
return ELoopSource::eSourceWin32;
}
bool Win32Dummy::WaitOnExt(AuUInt8 uFlags, AuUInt32 uTimeoutRelMS)
{
return this->WaitOn(uTimeoutRelMS);
}
bool Win32Dummy::WaitOnAbs(AuUInt64 uTimeoutAbs)
{
if (uTimeoutAbs)
{
auto uNow = AuTime::SteadyClockNS();
if (uNow >= uTimeoutAbs)
{
return this->IsSignaled();
}
auto uDiff = AuNSToMS<AuUInt64>(uTimeoutAbs - uNow);
if (!uDiff)
{
return this->IsSignaled();
}
return this->WaitOn(uDiff);
}
else
{
return this->WaitOn(0);
}
}
bool Win32Dummy::WaitOnAbsExt(AuUInt8 uFlags, AuUInt64 uTimeoutAbs)
{
return this->WaitOnAbs(uTimeoutAbs);
}
AUKN_SYM AuSPtr<ILoopSource> NewLSWin32Source(bool pumping)
{
AuSPtr<ILoopSource> ret;
if (!(ret = AuMakeShared<Win32Dummy>(pumping)))
{
return {};
}
return ret;
}
}