19 #ifndef HANGDETECTOR_UTILS_H
20 #define HANGDETECTOR_UTILS_H
27 #include <sys/types.h>
35 std::unique_ptr<std::thread> m_thread;
36 std::atomic_bool m_running {
false};
37 std::atomic_int m_resetCount {0};
38 std::atomic_int m_threshold {30};
44 std::this_thread::sleep_for(std::chrono::seconds(1));
45 if (m_resetCount > m_threshold)
47 printf(
"hang detected\n"); fflush(stdout);
48 kill(getpid(), SIGFPE);
50 else if (m_resetCount > (m_threshold / 2))
52 printf(
"hang detector will force crash in %d seconds...\n", m_threshold - m_resetCount); fflush(stdout);
65 const char* var = getenv(
"RTRMFPLAYER_HANG_DETECTOR_THRESHOLD_SEC");
70 int tmp = std::atoi(var);
93 g_timeout_add_seconds(1, [](gpointer data) -> gboolean {
95 return G_SOURCE_CONTINUE;
98 m_thread.reset(
new std::thread(&HangDetector::runWatchDog,
this));
110 #endif // HANGDETECTOR_H