From 4f991610d03609e4cfe06b4a1be694ce439b779b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 9 Apr 2025 01:48:21 +0100 Subject: watchdog: remove watchdog it has been unused for a while now --- src/helpers/Watchdog.cpp | 58 ------------------------------------------------ src/helpers/Watchdog.hpp | 34 ---------------------------- 2 files changed, 92 deletions(-) delete mode 100644 src/helpers/Watchdog.cpp delete mode 100644 src/helpers/Watchdog.hpp (limited to 'src/helpers') diff --git a/src/helpers/Watchdog.cpp b/src/helpers/Watchdog.cpp deleted file mode 100644 index 0956eed5..00000000 --- a/src/helpers/Watchdog.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "Watchdog.hpp" -#include -#include "config/ConfigManager.hpp" -#include "../config/ConfigValue.hpp" - -CWatchdog::~CWatchdog() { - m_bExitThread = true; - m_bNotified = true; - m_cvWatchdogCondition.notify_all(); - - if (m_pWatchdog && m_pWatchdog->joinable()) - m_pWatchdog->join(); -} - -CWatchdog::CWatchdog() : m_iMainThreadPID(pthread_self()) { - - m_pWatchdog = makeUnique([this] { - static auto PTIMEOUT = CConfigValue("debug:watchdog_timeout"); - - m_bWatchdogInitialized = true; - while (!m_bExitThread) { - std::unique_lock lk(m_mWatchdogMutex); - - if (!m_bWillWatch) - m_cvWatchdogCondition.wait(lk, [this] { return m_bNotified || m_bExitThread; }); - else if (!m_cvWatchdogCondition.wait_for(lk, std::chrono::milliseconds((int)(*PTIMEOUT * 1000.0)), [this] { return m_bNotified || m_bExitThread; })) - pthread_kill(m_iMainThreadPID, SIGUSR1); - - if (m_bExitThread) - break; - - m_bWatching = false; - m_bNotified = false; - } - }); -} - -void CWatchdog::startWatching() { - static auto PTIMEOUT = CConfigValue("debug:watchdog_timeout"); - - if (*PTIMEOUT == 0) - return; - - m_tTriggered = std::chrono::high_resolution_clock::now(); - m_bWillWatch = true; - m_bWatching = true; - - m_bNotified = true; - m_cvWatchdogCondition.notify_all(); -} - -void CWatchdog::endWatching() { - m_bWatching = false; - m_bWillWatch = false; - - m_bNotified = true; - m_cvWatchdogCondition.notify_all(); -} \ No newline at end of file diff --git a/src/helpers/Watchdog.hpp b/src/helpers/Watchdog.hpp deleted file mode 100644 index 51b71d13..00000000 --- a/src/helpers/Watchdog.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "memory/Memory.hpp" -#include -#include -#include - -class CWatchdog { - public: - // must be called from the main thread - CWatchdog(); - ~CWatchdog(); - - void startWatching(); - void endWatching(); - - std::atomic m_bWatchdogInitialized{false}; - - private: - std::chrono::high_resolution_clock::time_point m_tTriggered; - - pthread_t m_iMainThreadPID = 0; - - std::atomic m_bWatching = false; - std::atomic m_bWillWatch = false; - - UP m_pWatchdog; - std::mutex m_mWatchdogMutex; - std::atomic m_bNotified = false; - std::atomic m_bExitThread = false; - std::condition_variable m_cvWatchdogCondition; -}; - -inline UP g_pWatchdog; \ No newline at end of file -- cgit v1.2.3