2021-10-03 12:47:16 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: WaitSingle.NT.cpp
|
|
|
|
Date: 2021-10-1
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "WaitSingle.hpp"
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
namespace Aurora::IO::Loop
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
2022-04-12 21:26:15 +00:00
|
|
|
bool WaitSingleGeneric::WaitForAtleastOne(AuUInt32 timeout, const AuList<AuUInt> &handles, AuUInt &one)
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
|
|
|
if (handles.empty())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handles.size() == 1)
|
|
|
|
{
|
2022-03-30 17:56:56 +00:00
|
|
|
one = 0;
|
2022-04-15 18:20:12 +00:00
|
|
|
|
|
|
|
DWORD ret;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), timeout, true);
|
|
|
|
}
|
|
|
|
while (ret == WAIT_IO_COMPLETION);
|
|
|
|
|
|
|
|
return ret == WAIT_OBJECT_0;
|
2021-10-03 12:47:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AuList<HANDLE> ntHandles;
|
|
|
|
ntHandles.reserve(handles.size());
|
2022-04-12 21:26:15 +00:00
|
|
|
|
2021-10-03 12:47:16 +00:00
|
|
|
for (const auto &handle : handles)
|
|
|
|
{
|
2022-04-12 21:26:15 +00:00
|
|
|
if (!AuTryInsert(ntHandles, reinterpret_cast<HANDLE>(handle)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-03 12:47:16 +00:00
|
|
|
}
|
2022-03-30 17:56:56 +00:00
|
|
|
|
2022-04-12 21:26:15 +00:00
|
|
|
auto idx = WaitForMultipleObjectsEx(ntHandles.size(), ntHandles.data(), false, timeout, true);
|
2022-03-30 17:56:56 +00:00
|
|
|
if (idx < WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
one = handles[idx];
|
|
|
|
return true;
|
2021-10-03 12:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 21:26:15 +00:00
|
|
|
bool WaitSingleGeneric::WaitForOne(AuUInt32 timeout, AuUInt handle)
|
2022-03-30 17:56:56 +00:00
|
|
|
{
|
2022-04-15 18:20:12 +00:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handle), timeout, true);
|
|
|
|
}
|
|
|
|
while (ret == WAIT_IO_COMPLETION);
|
|
|
|
|
|
|
|
return ret == WAIT_OBJECT_0;
|
2022-03-30 17:56:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 12:47:16 +00:00
|
|
|
void WaitSingleGeneric::OnPresleep()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitSingleGeneric::OnFinishSleep()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ELoopSource WaitSingleGeneric::GetType()
|
|
|
|
{
|
|
|
|
return ELoopSource::eSourceInternalReserved1;
|
|
|
|
}
|
|
|
|
}
|