2022-05-13 18:24:27 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: WaitMultiple.Linux.cpp
|
|
|
|
Date: 2022-5-13
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "IO.hpp"
|
|
|
|
#include "WaitMultiple.Linux.hpp"
|
2022-06-12 13:53:35 +00:00
|
|
|
|
|
|
|
#include <Source/IO/Loop/Loop.hpp>
|
|
|
|
#include <Source/IO/Loop/LSHandle.hpp>
|
|
|
|
#include <Source/IO/Loop/LSEvent.hpp>
|
2022-05-13 18:24:27 +00:00
|
|
|
#include "UNIX/IOSubmit.Linux.hpp"
|
2022-06-12 13:53:35 +00:00
|
|
|
#include "FS/Async.Linux.hpp"
|
2022-05-13 18:24:27 +00:00
|
|
|
|
|
|
|
namespace Aurora::IO
|
|
|
|
{
|
|
|
|
AUKN_SYM AuUInt32 WaitMultiple(const AuList<AuSPtr<IAsyncTransaction>> &files, AuUInt32 timeout)
|
|
|
|
{
|
|
|
|
AuCtorCode_t code;
|
|
|
|
AuUInt32 count {};
|
|
|
|
|
2022-12-12 23:50:05 +00:00
|
|
|
AuUInt64 endTime = AuTime::SteadyClockMS() + AuUInt64(timeout);
|
2022-05-13 18:24:27 +00:00
|
|
|
|
|
|
|
auto waitQueue = AuTryConstruct<AuList<AuSPtr<IAsyncTransaction>>>(code, files);
|
|
|
|
if (!code)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (waitQueue.empty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt32 timeoutMS {};
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
{
|
2022-12-12 23:50:05 +00:00
|
|
|
AuInt64 delta = (AuInt64)endTime - AuTime::SteadyClockMS();
|
2022-05-13 18:24:27 +00:00
|
|
|
if (delta <= 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeoutMS = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!UNIX::LinuxOverlappedPoll(timeoutMS))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto itr = waitQueue.begin();
|
|
|
|
itr != waitQueue.end();)
|
|
|
|
{
|
|
|
|
if (AuStaticPointerCast<FS::LinuxAsyncFileTransaction>(*itr)->Complete())
|
|
|
|
{
|
|
|
|
count ++;
|
|
|
|
itr = waitQueue.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuList<AuSPtr<IAsyncTransaction>> WaitMultiple2(const AuList<AuSPtr<IAsyncTransaction>> &transactions, AuUInt32 requestedTimeoutMs)
|
|
|
|
{
|
|
|
|
AuCtorCode_t code;
|
|
|
|
AuList<AuSPtr<IAsyncTransaction>> retTransactions;
|
|
|
|
|
2022-12-12 23:50:05 +00:00
|
|
|
AuUInt64 endTime = AuTime::SteadyClockMS() + AuUInt64(requestedTimeoutMs);
|
2022-05-13 18:24:27 +00:00
|
|
|
|
|
|
|
auto waitQueue = AuTryConstruct<AuList<AuSPtr<IAsyncTransaction>>>(code, transactions);
|
|
|
|
if (!code)
|
|
|
|
{
|
2022-06-12 13:53:35 +00:00
|
|
|
SysPushErrorMem();
|
|
|
|
return {};
|
2022-05-13 18:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (waitQueue.empty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt32 timeoutMS {};
|
|
|
|
|
|
|
|
if (requestedTimeoutMs)
|
|
|
|
{
|
2022-12-12 23:50:05 +00:00
|
|
|
AuInt64 delta = (AuInt64)endTime - AuTime::SteadyClockMS();
|
2022-05-13 18:24:27 +00:00
|
|
|
if (delta <= 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeoutMS = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!UNIX::LinuxOverlappedPoll(timeoutMS))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto itr = waitQueue.begin();
|
|
|
|
itr != waitQueue.end();)
|
|
|
|
{
|
|
|
|
if (AuStaticPointerCast<FS::LinuxAsyncFileTransaction>(*itr)->Complete())
|
|
|
|
{
|
|
|
|
AuTryInsert(retTransactions, *itr);
|
|
|
|
itr = waitQueue.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retTransactions.size())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retTransactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void SendBatched()
|
|
|
|
{
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
UNIX::SendIOBuffers();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|