AuroraRuntime/Source/IO/Loop/LoopQueue.Linux.hpp
J Reece Wilson fd0c5b51b2 Further Linux support
[+] Begin work on IO futexes for io release on process/thread exit
[+] Linux ::readdir iteration
[+] AuConsole buffering API
[*] Fix sleep as to not get interrupted by signals
[*] Switch the type of FS lock used under Linux
[*] Linux: Use new IPCHandle encoding scheme
[*] Fix undefined behaviour: unintialized timeout values (AuLoop/Linux)
[*] Fix undefined behaviour: ConsoleTTY clear line was called of a color of a random value on stack
[-] Remainings of std dir iterator
[*] Fix pthread_kill (aka send signal to pthread handle) always kills process. This is what you expect bc signal handler inheritance.
[*] Reformat the build Aurora.json file
[+] Added clang warning ignores to the build file
[*] Fix: UNIX need to use STDOUT_FILENO. Was using CRT handle in place of fd by mistake.
[+] Linux implementation for IO yield (AuIO::IOYield() - UNIX::LinuxOverlappedYield())
[*] Fix: Linux async end of stream processing. res 0 = zero bytes consumed. <= was detecting this as an error of code 0. Should succeed with zero bytes.
[+] Linux LoopQueue missing epilogue hook for the IO processor
[*] Various refactors and minor bug fixes
[*] Linux fix: Handle pipe EOS as zero
[*] Linux fix: thread termination via a user signal of 77. Need a force terminate.
[*] IPC handle: fix improper int to bool cast in the header setup within ToString
[*] Linux fix: HWInfo CPU topology regression
[-] Linux fix: remove SIGABRT handler
[*] Missing override in compression, exit, and consoletty headers.
[+] Unix Syslog logger backend
2022-08-02 05:52:57 +01:00

134 lines
4.2 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LoopQueue.Linux.hpp
Date: 2022-4-4
Author: Reece
***/
#pragma once
#include "ILoopSourceEx.hpp"
#include "LSEvent.hpp"
namespace Aurora::IO::Loop
{
struct LoopQueue : ILoopQueue
{
LoopQueue();
~LoopQueue();
bool AddHook(const AuFunction<void()> &func);
bool Init();
void Deinit();
bool SourceAdd(const AuSPtr<ILoopSource> &source) override;
bool SourceAddWithTimeout(const AuSPtr<ILoopSource> &source, AuUInt32 ms) override;
bool SourceRemove(const AuSPtr<ILoopSource> &source) override;
AuUInt32 GetSourceCount() override;
virtual bool AddCallback(const AuSPtr<ILoopSource> &source, const AuSPtr<ILoopSourceSubscriber> &subscriber) override;
virtual bool AddCallbackEx(const AuSPtr<ILoopSource> &source, const AuSPtr<ILoopSourceSubscriberEx> &subscriber) override;
virtual bool AddCallback(const AuSPtr<ILoopSourceSubscriber> &subscriber) override;
void ChugPathConfigure(AuUInt32 sectionTickTime, AuSInt sectionDequeCount) override;
void ChugHint(bool value) override;
virtual bool Commit() override;
bool IsSignaledPeek() override;
AuUInt32 PumpNonblocking() override;
AuList<AuSPtr<ILoopSource>> PumpNonblockingEx() override;
bool WaitAll(AuUInt32 timeout) override;
AuUInt32 WaitAny(AuUInt32 timeout) override;
AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override;
AuUInt32 DoTick(AuUInt64, AuList<AuSPtr<ILoopSource>> *optOut = nullptr, bool *tryAgain = nullptr, bool async = false);
private:
void PumpHooks();
bool CommitDecommit();
struct SourceExtended
{
SourceExtended(LoopQueue *parent, const AuSPtr<ILoopSource> &source);
~SourceExtended();
void Deinit();
void Commit(const AuSPtr<SourceExtended> &self);
AuSPtr<ILoopSource> source;
ILoopSourceEx *sourceExtended {};
LoopQueue *parent {};
AuWPtr<SourceExtended> pin;
AuUInt64 timeoutAbs {};
bool ConsiderTimeout(AuUInt64 time) const
{
if ((timeoutAbs) && (time >= timeoutAbs))
{
for (const auto &handler : subscriberExs)
{
try
{
handler->OnTimeout(source);
}
catch (...)
{
SysPushErrorCatch();
}
}
return true;
}
return false;
}
AuList<AuSPtr<ILoopSourceSubscriber>> subscribers;
AuList<AuSPtr<ILoopSourceSubscriberEx>> subscriberExs;
bool bHasCommited {};
// ticked, should remove
AuTuple<bool, bool, bool> DoWork(int fd);
AuTuple<bool, bool, bool> DoWork(bool read, bool write);
};
struct AnEpoll
{
LoopQueue *parent {};
AuThreadPrimitives::SpinLock lock;
AuBST<int, int> startingWorkRead;
AuBST<int, int> startingWorkWrite;
void Add(SourceExtended *source);
void Remove(SourceExtended *source, bool readData, bool writeData);
};
int epollFd_{ -1 };
LSEvent lockStealer_;
AuThreadPrimitives::SpinLock commitQueueMutex_;
AuList<AuTuple<AuSPtr<ILoopSource>, AuSPtr<ILoopSourceSubscriber>, AuSPtr<ILoopSourceSubscriberEx>>> commitPending_;
AuList<AuSPtr<ILoopSource>> decommitQueue_;
AuThreadPrimitives::SpinLock globalLockMutex_;
AuList<AuSPtr<ILoopSourceSubscriber>> allSubscribers_;
AuThreadPrimitives::RWLockUnique_t sourceMutex_;
AuList<AuSPtr<SourceExtended>> sources_;
AuThreadPrimitives::RWLockUnique_t polledItemsMutex_;
AuList<AnEpoll *> alternativeEpolls_;
AuList<AuFunction<void()>> epilogueHooks_;
AnEpoll globalEpoll_;
};
}