28 std::size_t MaxServices = 16,
29 typename ClockPolicy = ChronoClockPolicy
61 const uint64_t now = nowNs();
66 void beat(uint32_t serviceId)
noexcept
68 _monitor.
beat(serviceId, nowNs());
76 template <
typename EventSinkType>
79 const uint64_t now = nowNs();
80 uint32_t timedOutId = 0;
81 uint64_t lastBeat = 0;
84 if (_monitor.
checkHealth(now, timedOutId, lastBeat, budget)) {
89 _kicksCount.fetch_add(1, std::memory_order_relaxed);
90 _lastHealthyTimeNs.store(now, std::memory_order_release);
95 _suppressionsCount.fetch_add(1, std::memory_order_relaxed);
103 return _kicksCount.load(std::memory_order_relaxed);
109 return _suppressionsCount.load(std::memory_order_relaxed);
113 [[nodiscard]]
static uint64_t nowNs() noexcept
115 if constexpr (std::is_integral_v<typename ClockPolicy::time_point>) {
116 return static_cast<uint64_t
>(ClockPolicy::now());
118 return static_cast<uint64_t
>(
119 std::chrono::duration_cast<std::chrono::nanoseconds>(
120 ClockPolicy::now().time_since_epoch()
126 HeartbeatMonitor<MaxServices> _monitor{};
128 void* _userData{
nullptr};
129 std::atomic<uint64_t> _kicksCount{0};
130 std::atomic<uint64_t> _suppressionsCount{0};
131 std::atomic<uint64_t> _lastHealthyTimeNs{0};
Hardware and simulated clock policies (Chrono, Manual, Tick, EspTimer, FreeRTOS).
Lock-free SLA deadline tracker for multi-service heartbeats.
Heartbeat and fault notification event structures.
Zero-heap multi-service heartbeat tracker for safety-critical execution. Thread-safe for concurrent h...
Definition HeartbeatMonitor.hpp:21
bool checkHealth(uint64_t nowNs, uint32_t &outTimedOutServiceId, uint64_t &outLastHeartbeatNs, uint64_t &outTimeoutBudgetNs) const noexcept
Check health status of all registered active services.
Definition HeartbeatMonitor.hpp:87
bool registerService(uint32_t serviceId, uint64_t timeoutNs, uint64_t initialTimestampNs=0) noexcept
Register a service for heartbeat monitoring with a specified timeout.
Definition HeartbeatMonitor.hpp:37
void beat(uint32_t serviceId, uint64_t nowNs) noexcept
Record a heartbeat for a given service.
Definition HeartbeatMonitor.hpp:60
Dedicated safety supervisor monitoring subsystem heartbeats and controlling watchdog refresh....
Definition WatchdogSupervisor.hpp:31
void beat(uint32_t serviceId) noexcept
Submit a heartbeat for a monitored service.
Definition WatchdogSupervisor.hpp:66
HeartbeatMonitor< MaxServices > & heartbeatMonitor() noexcept
Access reference to the internal HeartbeatMonitor.
Definition WatchdogSupervisor.hpp:47
bool supervise(const EventSinkType &sink) noexcept
Perform a supervisor check iteration. Kicks the hardware watchdog if healthy; suppresses the kick and...
Definition WatchdogSupervisor.hpp:77
void(*)(void *userData) KickCallbackFn
Definition WatchdogSupervisor.hpp:33
bool registerService(uint32_t serviceId, uint64_t timeoutNs) noexcept
Register a service for supervision.
Definition WatchdogSupervisor.hpp:59
const HeartbeatMonitor< MaxServices > & heartbeatMonitor() const noexcept
Access const reference to the internal HeartbeatMonitor.
Definition WatchdogSupervisor.hpp:53
uint64_t totalKicks() const noexcept
Get total number of successful watchdog kicks.
Definition WatchdogSupervisor.hpp:101
void setWatchdogKickCallback(KickCallbackFn kickFn, void *userData=nullptr) noexcept
Configure the physical hardware/software watchdog kick callback.
Definition WatchdogSupervisor.hpp:40
uint64_t totalSuppressions() const noexcept
Get total number of watchdog kick suppressions due to health violations.
Definition WatchdogSupervisor.hpp:107
WatchdogSupervisor()=default
Definition CircuitBreaker.hpp:13
Dispatched when a monitored service fails to deliver its heartbeat within its timeout window.
Definition SafetyEvents.hpp:15
uint32_t serviceId
Definition SafetyEvents.hpp:16