/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: MTWatchDog.cpp Date: 2022-2-3 Author: Reece ***/ #include #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()); } }