From f60aec8607aa4ef70b4653d201c854b00a538951 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 21 Mar 2024 13:03:41 +0100 Subject: harden attach sponsor process (#14) - Improvement: Delay exiting due to no sponsor processes by one second to handle race conditions - Improvement: Safer IsProcessRunning check - Improvement: make sure we can RequestApplicationExit safely from any thread --- src/zencore/zencore.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/zencore/zencore.cpp') diff --git a/src/zencore/zencore.cpp b/src/zencore/zencore.cpp index d0acac608..b80b1d280 100644 --- a/src/zencore/zencore.cpp +++ b/src/zencore/zencore.cpp @@ -115,11 +115,16 @@ IsApplicationExitRequested() return s_ApplicationExitRequested; } -void +bool RequestApplicationExit(int ExitCode) { - s_ApplicationExitCode = ExitCode; - s_ApplicationExitRequested = true; + bool Expected = false; + if (s_ApplicationExitRequested.compare_exchange_weak(Expected, true)) + { + s_ApplicationExitCode = ExitCode; + return true; + } + return false; } int -- cgit v1.2.3