Apply Ocamlvalue derive to oxidized aast related types
[hiphop-php.git] / hphp / hack / src / utils / parent / parentimpl.cpp
blobf4fa89007ec755ae35a98b69dd3fa7fbe4cc9979
1 #include <thread>
2 #include <mutex>
3 #include <cassert>
4 #include <atomic>
6 #include <unistd.h>
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 {
16 assert(interval > 0);
17 assert(grace > 0);
18 for (;;) {
19 // when we get reparented
20 // exit immediately
21 if (getppid() == 1) {
22 sleep(static_cast<unsigned>(grace));
23 exit(20);
25 sleep(static_cast<unsigned>(interval));
30 extern "C" void exit_on_parent_exit_(int interval, int grace) noexcept {
31 assert(interval > 0);
32 assert(grace > 0);
33 std::lock_guard<std::mutex> guard(watchdog_mut);
34 assert(watchdog_count == 0 || watchdog_count == 1);
35 if (watchdog_count == 0) {
36 ++watchdog_count;
37 std::thread t(check_and_die, interval, grace);
38 t.detach();
40 return;
43 extern "C" int get_watchdog_count_() noexcept {
44 std::lock_guard<std::mutex> guard(watchdog_mut);
45 return watchdog_count;