MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / check_watchdog

Method check_watchdog

OpenHD/ohd_common/src/openhd_util_async.cpp:93–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93void openhd::AsyncHandle::check_watchdog() {
94 while (m_watchdog_run) {
95 { // Let the mutex go out of scope before sleeping
96 std::lock_guard<std::mutex> lock(m_threads_mutex);
97 m_tasks.erase(std::remove_if(m_tasks.begin(), m_tasks.end(),
98 [](std::shared_ptr<RunningTask>& task) {
99 // returns true if task is done
100 return terminate_when_done(*task);
101 }),
102 m_tasks.end());
103 for (auto& task : m_tasks) {
104 const auto elapsed_task =
105 std::chrono::steady_clock::now() - task->start_time;
106 if (elapsed_task > std::chrono::seconds(10)) {
107 // Log a warning message every 3 seconds on a (presumably) hanging
108 // task
109 if (std::chrono::steady_clock::now() - task->last_watchdog_error_log >
110 std::chrono::seconds(3)) {
111 openhd::log::get_default()->warn("Async Task [{}] hanging ?",
112 task->tag);
113 }
114 }
115 }
116 }
117 std::this_thread::sleep_for(std::chrono::seconds(1));
118 }
119}
120
121int openhd::AsyncHandle::get_n_current_tasks() {
122 std::lock_guard<std::mutex> lock(m_threads_mutex);

Callers

nothing calls this directly

Calls 3

eraseMethod · 0.80
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected