MCPcopy Create free account
hub / github.com/XpuOS/xsched / Create

Method Create

utils/src/waitpid.cpp:28–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using namespace xsched::utils;
27
28std::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

Callers

nothing calls this directly

Calls 1

GetProcessIdFunction · 0.85

Tested by

no test coverage detected