[fix] fix restart/shutdown races in process monitor

This commit is contained in:
dijunkun
2026-03-20 14:50:42 +08:00
parent 56c0bca62f
commit 38b7775b1b
2 changed files with 82 additions and 59 deletions
+6 -8
View File
@@ -7,11 +7,11 @@
#ifndef _DAEMON_H_
#define _DAEMON_H_
#include <atomic>
#include <csignal>
#include <functional>
#include <string>
#define DAEMON_DEFAULT_RESTART_DELAY_MS 1000
class Daemon {
public:
using MainLoopFunc = std::function<void()>;
@@ -28,12 +28,10 @@ class Daemon {
std::string name_;
bool runWithRestart(MainLoopFunc loop);
#ifdef _WIN32
bool running_;
#else
static Daemon* instance_;
volatile bool running_;
#ifndef _WIN32
static volatile std::sig_atomic_t stop_requested_;
#endif
std::atomic<bool> running_;
};
#endif
#endif