AuroraRuntime/Source/Loop/WaitSingle.Unix.cpp
J Reece Wilson 3defb1bb14 [+] Linux Watcher
[*] Expand watcher API -> Breaking NT
[*] Reexpand loop queue API -> Breaking NT
[*] Linux CPUInfo clean up
[*] Bug fix: mkdir should set execute flag... because directories are special
[*] Refactor: Cleanup base64
[*] Bug fix: UNIX path normalization
[*] Bug fix: missing O_CREAT flag (au auto-creates)
[*] Normalize line endings
2022-04-10 16:40:49 +01:00

113 lines
2.4 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WaitSingle.Unix.cpp
Date: 2022-4-4
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "WaitSingle.hpp"
namespace Aurora::Loop
{
bool WaitSingleGeneric::WaitForAtleastOne(const AuList<AuUInt> &handles, const AuList<AuUInt> &handlesWrite, AuUInt &one, AuUInt &two)
{
fd_set readSet, writeSet;
AuUInt maxHandle {};
struct timeval tv {};
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
for (const auto i : handles)
{
if (i == -1) continue;
FD_SET(i, &readSet);
maxHandle = AuMax(maxHandle, i + 1);
}
for (const auto i : handlesWrite)
{
if (i == -1) continue;
FD_SET(i, &writeSet);
maxHandle = AuMax(maxHandle, i + 1);
}
auto active = select(maxHandle, handles.size() ? &readSet : NULL, handlesWrite.size() ? &writeSet : NULL, NULL, &tv);
if (active == -1)
{
// todo push error
return false;
}
for (const auto i : handles)
{
if (!FD_ISSET(i, &readSet))
{
continue;
}
one = i;
break;
}
for (const auto i : handlesWrite)
{
if (!FD_ISSET(i, &writeSet))
{
continue;
}
two = i;
break;
}
return true;
}
bool WaitSingleGeneric::WaitForOne(AuUInt read, AuUInt write)
{
fd_set readSet, writeSet;
struct timeval tv {};
int maxFd {};
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
if (read != -1)
{
maxFd = read + 1;
FD_SET(read, &readSet);
}
if (write != -1)
{
FD_SET(write, &writeSet);
maxFd = AuMax(maxFd, int(write) + 1);
}
auto active = select(maxFd, read != -1 ? &readSet : NULL, write != -1 ? &writeSet : NULL, NULL, &tv);
if (active == -1)
{
// todo push error
return false;
}
return active == 1;
}
void WaitSingleGeneric::OnPresleep()
{
}
void WaitSingleGeneric::OnFinishSleep()
{
}
ELoopSource WaitSingleGeneric::GetType()
{
return ELoopSource::eSourceInternalReserved1;
}
}