142 lines
3.4 KiB
C++
142 lines
3.4 KiB
C++
/***
|
|
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"
|
|
#include "FS/Async.Linux.hpp"
|
|
#include "UNIX/IOSubmit.Linux.hpp"
|
|
|
|
namespace Aurora::IO
|
|
{
|
|
AUKN_SYM AuUInt32 WaitMultiple(const AuList<AuSPtr<IAsyncTransaction>> &files, AuUInt32 timeout)
|
|
{
|
|
AuCtorCode_t code;
|
|
AuUInt32 count {};
|
|
|
|
AuUInt64 endTime = AuTime::CurrentInternalClockMS() + AuUInt64(timeout);
|
|
|
|
auto waitQueue = AuTryConstruct<AuList<AuSPtr<IAsyncTransaction>>>(code, files);
|
|
if (!code)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
if (waitQueue.empty())
|
|
{
|
|
break;
|
|
}
|
|
|
|
AuUInt32 timeoutMS {};
|
|
|
|
if (timeout)
|
|
{
|
|
AuInt64 delta = (AuInt64)endTime - AuTime::CurrentInternalClockMS();
|
|
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;
|
|
|
|
AuUInt64 endTime = AuTime::CurrentInternalClockMS() + AuUInt64(requestedTimeoutMs);
|
|
|
|
auto waitQueue = AuTryConstruct<AuList<AuSPtr<IAsyncTransaction>>>(code, transactions);
|
|
if (!code)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
if (waitQueue.empty())
|
|
{
|
|
break;
|
|
}
|
|
|
|
AuUInt32 timeoutMS {};
|
|
|
|
if (requestedTimeoutMs)
|
|
{
|
|
AuInt64 delta = (AuInt64)endTime - AuTime::CurrentInternalClockMS();
|
|
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
|
|
}
|
|
} |