diff options
| author | Martin Ridgers <[email protected]> | 2022-01-07 14:24:12 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2022-01-07 14:24:12 +0100 |
| commit | 8580a242b6f864b9f9cefbc5723068788ca2076f (patch) | |
| tree | ca873c636e4019ad94e399ca23aacca724bd4776 /zencore/thread.cpp | |
| parent | Use null-signal kill() to determine if a PID is valid (diff) | |
| download | zen-8580a242b6f864b9f9cefbc5723068788ca2076f.tar.xz zen-8580a242b6f864b9f9cefbc5723068788ca2076f.zip | |
Use POSIX implementation for ProcessHandle on Mac
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp index c710930a6..358256b1d 100644 --- a/zencore/thread.cpp +++ b/zencore/thread.cpp @@ -622,13 +622,11 @@ ProcessHandle::Initialize(int Pid) #if ZEN_PLATFORM_WINDOWS m_ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, Pid); -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC if (Pid > 0) { m_ProcessHandle = (void*)(intptr_t(Pid)); } -#else -# error Check process control on this platform #endif if (!m_ProcessHandle) @@ -649,10 +647,8 @@ ProcessHandle::IsRunning() const DWORD ExitCode = 0; GetExitCodeProcess(m_ProcessHandle, &ExitCode); bActive = (ExitCode == STILL_ACTIVE); -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC bActive = (kill(pid_t(m_Pid), 0) == 0); -#else -# error Check process control on this platform #endif return bActive; @@ -678,11 +674,9 @@ ProcessHandle::Terminate(int ExitCode) TerminateProcess(m_ProcessHandle, ExitCode); DWORD WaitResult = WaitForSingleObject(m_ProcessHandle, INFINITE); bSuccess = (WaitResult != WAIT_OBJECT_0); -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC ZEN_UNUSED(ExitCode); - bSuccess = (kill(m_Pid, SIGKILL) == 0); -#else -# error Check kill() on this platform + bSuccess = (kill(m_Pid, SIGKILL) == 0); #endif if (!bSuccess) @@ -725,7 +719,7 @@ ProcessHandle::Wait(int TimeoutMs) case WAIT_FAILED: break; } -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC const int SleepMs = 20; timespec SleepTime = {0, SleepMs * 1000 * 1000}; for (int i = 0;; i += SleepMs) @@ -749,8 +743,6 @@ ProcessHandle::Wait(int TimeoutMs) nanosleep(&SleepTime, nullptr); } -#else -# error Check kill() on this platform #endif // What might go wrong here, and what is meaningful to act on? |