AuroraRuntime/Source/Exit/AuMTWatchDog.cpp

47 lines
1.3 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuMTWatchDog.cpp
Date: 2022-2-3
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuExit.hpp"
#include "AuMTWatchDog.hpp"
namespace Aurora::Exit
{
struct MTWatchDog : AuThreads::IThreadFeature
{
void Init() override;
// OSThread tls clears should call us first.
// if the main thread has valid tls, grug will be informed (sanz type beat, informing hairy beasts)
void Cleanup() override;
};
void MTWatchDog::Init()
{
}
void MTWatchDog::Cleanup()
{
// Flush all internal consoles on shutdown
if (!gHasSentTerminate)
{
SysPushErrorTimeoutError("Program never executed runtime shutdown -> announcing abnormal shutdown");
PostLevel(AuThreads::GetThread(), ETriggerLevel::eProblematicEvent);
PostLevel(AuThreads::GetThread(), ETriggerLevel::eSafeTermination);
if (Aurora::RuntimeHasStarted())
{
Aurora::RuntimeShutdown();
}
}
}
void InitWatchdog()
{
// Add a 'MTWatchDog' object to the main threads TLS hook
AuThreads::GetThread()->AddLastHopeTlsHook(AuMakeShared<MTWatchDog>());
}
}