scc 2025.09
SystemC components library
watchdog.h
1/*******************************************************************************
2 * Copyright 2017 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#pragma once
18#include <atomic>
19#ifdef noexcept
20#undef noexcept
21#endif
22#include <chrono>
23#include <condition_variable>
24#include <functional>
25#include <mutex>
26#include <thread>
27
33namespace util {
37class watchdog {
38public:
46 watchdog(std::chrono::system_clock::duration timeout, std::function<void(void)> alarm_cb,
47 std::chrono::system_clock::duration sleep_duration);
54 watchdog(std::chrono::system_clock::duration timeout, std::function<void(void)> alarm);
58 ~watchdog();
59
60 watchdog(const watchdog&) = delete;
61
62 watchdog& operator=(const watchdog&) = delete;
63
64 watchdog(watchdog&&) = delete;
65
66 watchdog& operator=(watchdog&&) = delete;
67
71 void arm();
75 void re_arm();
76
77private:
78 void guard();
79
80 std::chrono::system_clock::duration timeout;
81 std::chrono::system_clock::duration sleep_duration;
82 std::function<void(void)> alarm_cb;
83 std::atomic_bool idle{true};
84 std::atomic_bool live{true};
85 std::atomic<std::chrono::system_clock::time_point> touched{std::chrono::system_clock::now()};
86 std::thread guard_thread;
87 std::mutex guard_mutex;
88 std::condition_variable wakeup;
89};
90} // namespace util
watchdog(std::chrono::system_clock::duration timeout, std::function< void(void)> alarm)
watchdog(std::chrono::system_clock::duration timeout, std::function< void(void)> alarm_cb, std::chrono::system_clock::duration sleep_duration)
SCC common utilities.
Definition bit_field.h:30