Reece
e5e36bd887
[*] Fix deadlock in the async subsystem (NoLockShutdown vs Shutdown in exception handler) [+] Added ProccessMap NT variant [+] Added ToolHelp image profiling [*] Improved exception awareness [*] Delegated SpawnThread to isolated TU, ready for reuse for RunAs and XNU Open - now with horrible evil alloc that could fail [+] Added header for future api 'UtilRun' [*] Improve NT core detection [*] Changed small affinity bitmap to AuUInt64 instead of AuUInt32 [+] Added data structure to hold cpuids/affinity masks [+] Implemented logger sinks [+] Implemented logger glue logic [*] Began migrating older loggers to sink-based default devices [*] Minor refactors [*] Improved internal exception discarding, not yet nothrow capable [*] Minor create directory fix
109 lines
2.5 KiB
C++
109 lines
2.5 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"
|
|
#include "Logging/Logger.hpp"
|
|
|
|
namespace Aurora::Console
|
|
{
|
|
static AuThreads::ThreadUnique_t gWriterThread;
|
|
static AuThreadPrimitives::ConditionVariableUnique_t gCondVar;
|
|
static AuThreadPrimitives::ConditionMutexUnique_t gMutex;
|
|
|
|
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()
|
|
{
|
|
SlowStartupTasks();
|
|
|
|
AU_LOCK_GUARD(gMutex);
|
|
|
|
while (AuIsThreadRunning())
|
|
{
|
|
gCondVar->WaitForSignal(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>());
|
|
|
|
gMutex = AuThreadPrimitives::ConditionMutexUnique();
|
|
SysAssert(gMutex);
|
|
|
|
gCondVar = AuThreadPrimitives::ConditionVariableUnique(AuUnsafeRaiiToShared(gMutex));
|
|
SysAssert(gCondVar);
|
|
|
|
InitFlushThread();
|
|
}
|
|
|
|
void PingFlushers()
|
|
{
|
|
if (gCondVar)
|
|
{
|
|
gCondVar->Signal();
|
|
}
|
|
}
|
|
|
|
void DeinitFlusher()
|
|
{
|
|
DestroyFlushThread();
|
|
}
|
|
|
|
void ForceFlush()
|
|
{
|
|
Logging::ForceFlushLoggers();
|
|
ConsoleFIO::Flush();
|
|
}
|
|
} |