AuroraRuntime/Source/Console/Flusher.cpp
Reece 99c5e1fa65 A pretty large patch not worth breaking up into separate commits
[*] Split up Aurora Async
[*] Split Async app into seperate ThreadPool concept
[*] Fix various OSThread bugs and tls transfer issues
[*] Set default affinity to 0xFFFFFFFF
[*] Update Build script
[+] Add AuTuplePopFront
[+] New Network Interface (unimplemented)
[*] Stub out the interfaces required for a better logger
[*] Fix Win32 ShellExecute bug; windows 11 struggles without explicit com init per the docs - now deferring to thread pool
[*] Update gitignore
[*] Follow XDG home standard
[*] Refactor some namespaces to use the shorthand aliases
[*] Various stability fixes
2021-11-05 17:34:23 +00:00

90 lines
2.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Flusher.cpp
Date: 2021-8-27
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Flusher.hpp"
#include "ConsoleFIO/ConsoleFIO.hpp"
namespace Aurora::Console
{
static AuThreads::ThreadUnique_t gWriterThread;
class ShutdownFlushHook : public AuThreads::IThreadFeature
{
public:
void Init() override;
void Cleanup() override;
};
void ShutdownFlushHook::Init()
{
}
void ShutdownFlushHook::Cleanup()
{
// Flush all internal consoles on shutdown
ForceFlush();
}
static void SlowStartupTasks()
{
ConsoleFIO::FIOCleanup();
}
static void LogThreadEP()
{
auto thread = AuThreads::GetThread();
SlowStartupTasks();
while (!thread->Exiting())
{
Threading::Sleep(500);
ForceFlush();
}
}
static void DestroyFlushThread()
{
gWriterThread.reset();
}
static void InitFlushThread()
{
// Startup a runner thread that will take care of all the stress inducing IO every so often on a remote thread
gWriterThread = AuThreads::ThreadUnique(AuThreads::ThreadInfo(
AuMakeShared<AuThreads::IThreadVectorsFunctional>(AuThreads::IThreadVectorsFunctional::OnEntry_t(std::bind(LogThreadEP)),
AuThreads::IThreadVectorsFunctional::OnExit_t{}),
"CasualConsoleAsyncWritter"
));
if (!gWriterThread)
{
return;
}
gWriterThread->Run();
}
void InitFlusher()
{
// Add a 'ShutdownFlushHook' object to the main threads TLS hook
AuThreads::GetThread()->AddLastHopeTlsHook(AuMakeShared<ShutdownFlushHook>());
InitFlushThread();
}
void DeinitFlusher()
{
DestroyFlushThread();
}
void ForceFlush()
{
ConsoleFIO::Flush();
}
}