AuroraRuntime/Source/Exit/MTWatchDog.cpp
Reece cd8cfd4f1c [+] Shutdown runtime on unsafe main thread termination
[+] Grug will flush everything inline on deinit
[*] Fix bug in BufferedCharConsumer, didn't return char in peak (doh)
2022-02-21 03:40:29 +00:00

48 lines
1.3 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: MTWatchDog.cpp
Date: 2022-2-3
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Exit/Exit.hpp"
#include "MTWatchDog.hpp"
namespace Aurora::Exit
{
class MTWatchDog : public AuThreads::IThreadFeature
{
public:
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>());
}
}