| 26 | using namespace xsched::utils; |
| 27 | |
| 28 | std::unique_ptr<PidWaiter> PidWaiter::Create(TerminateCallback callback) |
| 29 | { |
| 30 | if (callback == nullptr) XERRO("callback is nullptr"); |
| 31 | |
| 32 | #if defined(__linux__) |
| 33 | // check if the system supports pidfd_open |
| 34 | int self_pid_fd = PidFdWaiter::OpenPidFd(GetProcessId(), 0); |
| 35 | if (self_pid_fd == -1) { |
| 36 | XWARN("pidfd_open is not supported, using scan method, which may consume more CPU"); |
| 37 | return std::make_unique<ScanPidWaiter>(callback); |
| 38 | } |
| 39 | |
| 40 | XASSERT(!close(self_pid_fd), "fail to close self pid fd"); |
| 41 | XINFO("pidfd_open is supported, using pidfd_wait method"); |
| 42 | return std::make_unique<PidFdWaiter>(callback); |
| 43 | #elif defined(_WIN32) |
| 44 | return std::make_unique<WinPidWaiter>(callback); |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | #if defined(__linux__) |
| 49 |
nothing calls this directly
no test coverage detected