From 5eac984757b5db8c637641c290dd7872d1dc0a89 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 3 Mar 2025 13:34:45 +0000 Subject: [PATCH] chore: Add mutex for process state management in MSWindowsWatchdog --- src/lib/platform/MSWindowsWatchdog.cpp | 8 +++++++- src/lib/platform/MSWindowsWatchdog.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index 256b45b8b..8bae796af 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -171,6 +171,8 @@ void MSWindowsWatchdog::mainLoop(void *) LOG_DEBUG("starting watchdog main loop"); while (m_running) { + std::unique_lock lock(m_processStateMutex); + if (!m_command.empty() && !m_foreground && m_session.hasChanged()) { LOG_DEBUG("session changed, queueing process start"); m_processState = ProcessState::StartPending; @@ -228,6 +230,8 @@ void MSWindowsWatchdog::mainLoop(void *) } break; } + lock.unlock(); + // TODO: This seems like a hack, why would we need to send the SAS function every loop iteration? // This slows down both the process relaunch speed and the watchdog thread loop shut down time. sendSas(); @@ -328,7 +332,9 @@ void MSWindowsWatchdog::startProcess() void MSWindowsWatchdog::setProcessConfig(const std::string_view &command, bool elevate) { - LOG_DEBUG("watchdog process config updated"); + LOG_DEBUG("updating watchdog process config"); + std::unique_lock lock(m_processStateMutex); + m_command = command; m_elevateProcess = elevate; diff --git a/src/lib/platform/MSWindowsWatchdog.h b/src/lib/platform/MSWindowsWatchdog.h index 2ee72e6a1..71188a132 100644 --- a/src/lib/platform/MSWindowsWatchdog.h +++ b/src/lib/platform/MSWindowsWatchdog.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -161,4 +162,5 @@ private: ProcessState m_processState = ProcessState::Idle; std::string m_command = ""; SendSas m_sendSasFunc = nullptr; + std::mutex m_processStateMutex; };