AuroraRuntime/Source/IO/WaitMultiple.NT.cpp
Jamie Reece Wilson 60bb1020ce [+] bool WaitMultipleLoopSources(const AuList<AuSPtr<Loop::ILoopSource>> &lsList,
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
                                 bool bAny = true,
                                 AuOptionalEx<AuUInt32> uTimeoutMS = 0);
2023-10-21 06:10:33 +01:00

93 lines
2.5 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 {};
}
AuDebug::AddMemoryCrunch();
AuTryReserve(retTransasctions, transactions.size());
for (const auto &file : transactions)
{
SysAssert(AuTryInsert(handles, AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->GetHandle()));
}
AuDebug::DecMemoryCrunch();
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())
{
AuDebug::AddMemoryCrunch();
SysAssert(AuTryInsert(retTransasctions, file));
AuDebug::DecMemoryCrunch();
}
}
return retTransasctions;
}
AUKN_SYM void SendBatched()
{
}
AUKN_SYM AuUInt32 WaitMultipleLoopSources(const AuList<AuSPtr<Loop::ILoopSource>> &lsList, bool bAny, AuOptionalEx<AuUInt32> uTimeoutMS);
}