AuroraRuntime/Source/IO/WaitMultiple.NT.cpp
Reece 86ac108f11 [*] Move AuIO::WaitMultiple
[+] AuIO::WaitMultiple2
2022-05-13 19:25:29 +01:00

85 lines
2.1 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WaitMultiple.NT.cpp
Date: 2022-5-13
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IO.hpp"
#include "WaitMultiple.NT.hpp"
#include "FS/Async.NT.hpp"
namespace Aurora::IO
{
AUKN_SYM AuUInt32 WaitMultiple(const AuList<AuSPtr<IAsyncTransaction>> &files, AuUInt32 timeout)
{
AuList<HANDLE> handles;
AuUInt32 count {};
if (files.empty())
{
return 0;
}
for (const auto &file : files)
{
AuTryInsert(handles, AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->GetHandle());
}
auto ret = WaitForMultipleObjectsEx(handles.size(), handles.data(), false, timeout ? timeout : INFINITE, TRUE);
if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED)
{
return 0;
}
for (auto &file : files)
{
count += AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->Complete();
}
return count;
}
AUKN_SYM AuList<AuSPtr<IAsyncTransaction>> WaitMultiple2(const AuList<AuSPtr<IAsyncTransaction>> &transactions, AuUInt32 timeoutMs)
{
AuList<AuSPtr<IAsyncTransaction>> retTransasctions;
AuList<HANDLE> handles;
AuUInt32 count {};
if (transactions.empty())
{
return {};
}
retTransasctions.reserve(transactions.size());
for (const auto &file : transactions)
{
AuTryInsert(handles, AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->GetHandle());
}
auto ret = WaitForMultipleObjectsEx(handles.size(), handles.data(), false, timeoutMs ? timeoutMs : INFINITE, TRUE);
if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED)
{
return {};
}
for (auto &file : transactions)
{
if (AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->Complete())
{
AuTryInsert(retTransasctions, file);
}
}
return retTransasctions;
}
AUKN_SYM void SendBatched()
{
}
}