8 #include "parentimpl.h"
11 std::mutex watchdog_mut
;
12 static int watchdog_count
= 0;
15 static void check_and_die(int interval
, int grace
) noexcept
{
19 // when we get reparented
22 sleep(static_cast<unsigned>(grace
));
25 sleep(static_cast<unsigned>(interval
));
30 extern "C" void exit_on_parent_exit_(int interval
, int grace
) noexcept
{
33 std::lock_guard
<std::mutex
> guard(watchdog_mut
);
34 assert(watchdog_count
== 0 || watchdog_count
== 1);
35 if (watchdog_count
== 0) {
37 std::thread
t(check_and_die
, interval
, grace
);
43 extern "C" int get_watchdog_count_() noexcept
{
44 std::lock_guard
<std::mutex
> guard(watchdog_mut
);
45 return watchdog_count
;