2022-05-13 18:24:27 +00:00
|
|
|
/***
|
|
|
|
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 {};
|
|
|
|
}
|
2023-04-26 06:24:17 +00:00
|
|
|
|
|
|
|
AuDebug::AddMemoryCrunch();
|
2022-05-13 18:24:27 +00:00
|
|
|
|
2023-04-26 06:24:17 +00:00
|
|
|
AuTryReserve(retTransasctions, transactions.size());
|
2022-05-13 18:24:27 +00:00
|
|
|
|
|
|
|
for (const auto &file : transactions)
|
|
|
|
{
|
2023-04-26 06:24:17 +00:00
|
|
|
SysAssert(AuTryInsert(handles, AuStaticPointerCast<FS::NtAsyncFileTransaction>(file)->GetHandle()));
|
2022-05-13 18:24:27 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 06:24:17 +00:00
|
|
|
AuDebug::DecMemoryCrunch();
|
|
|
|
|
2022-05-13 18:24:27 +00:00
|
|
|
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())
|
|
|
|
{
|
2023-04-26 06:24:17 +00:00
|
|
|
AuDebug::AddMemoryCrunch();
|
|
|
|
SysAssert(AuTryInsert(retTransasctions, file));
|
|
|
|
AuDebug::DecMemoryCrunch();
|
2022-05-13 18:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retTransasctions;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void SendBatched()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-10-21 05:10:33 +00:00
|
|
|
|
|
|
|
AUKN_SYM AuUInt32 WaitMultipleLoopSources(const AuList<AuSPtr<Loop::ILoopSource>> &lsList, bool bAny, AuOptionalEx<AuUInt32> uTimeoutMS);
|
2022-05-13 18:24:27 +00:00
|
|
|
}
|