Chromium Code Reviews| Index: runtime/bin/process_linux.cc |
| diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc |
| index 5cd52fb38285302ddfb7c2aa956da8586a793d20..355b8e629a75f4f32bb24899b950ddbae7d30ffc 100644 |
| --- a/runtime/bin/process_linux.cc |
| +++ b/runtime/bin/process_linux.cc |
| @@ -101,6 +101,8 @@ dart::Mutex ProcessInfoList::mutex_; |
| // event loop. |
| class ExitCodeHandler { |
| public: |
| + static const uint8_t kThreadTerminateByte = 1; |
|
Ivan Posva
2012/02/01 18:09:24
Why public? This is only used from within ExitCode
Mads Ager (google)
2012/02/01 18:15:18
Good point. Done.
|
| + |
| // Ensure that the ExitCodeHandler has been initialized. |
| static bool EnsureInitialized() { |
| // Multiple isolates could be starting processes at the same |
| @@ -136,6 +138,33 @@ class ExitCodeHandler { |
| return sig_chld_fds_[1]; |
| } |
| + static void TerminateExitCodeThread() { |
| + MutexLocker locker(&mutex_); |
| + if (!initialized_) { |
| + return; |
| + } |
| + |
| + uint8_t data = kThreadTerminateByte; |
| + ssize_t result = |
| + TEMP_FAILURE_RETRY(write(ExitCodeHandler::WakeUpFd(), &data, 1)); |
| + if (result < 1) { |
| + perror("Failed to write to wake-up fd to terminate exit code thread"); |
| + } |
| + |
| + { |
| + MonitorLocker terminate_locker(&thread_terminate_monitor_); |
| + while (!thread_terminated_) { |
| + terminate_locker.Wait(); |
| + } |
| + } |
| + } |
| + |
| + static void ExitCodeThreadTerminated() { |
| + MonitorLocker locker(&thread_terminate_monitor_); |
| + thread_terminated_ = true; |
| + locker.Notify(); |
| + } |
| + |
| private: |
| // GetProcessExitCodes is called on a separate thread when a SIGCHLD |
| // signal is received to retrieve the exit codes and post them to |
| @@ -188,6 +217,10 @@ class ExitCodeHandler { |
| if (read_bytes < 1) { |
| perror("Failed to read from wake-up fd in exit-code handler"); |
| } |
| + if (data == ExitCodeHandler::kThreadTerminateByte) { |
| + ExitCodeThreadTerminated(); |
| + return; |
| + } |
| // Get the exit code from all processes that have died. |
| GetProcessExitCodes(); |
| } |
| @@ -197,12 +230,16 @@ class ExitCodeHandler { |
| static dart::Mutex mutex_; |
| static bool initialized_; |
| static int sig_chld_fds_[2]; |
| + static bool thread_terminated_; |
| + static dart::Monitor thread_terminate_monitor_; |
| }; |
| dart::Mutex ExitCodeHandler::mutex_; |
| bool ExitCodeHandler::initialized_ = false; |
| int ExitCodeHandler::sig_chld_fds_[2] = { 0, 0 }; |
| +bool ExitCodeHandler::thread_terminated_ = false; |
| +dart::Monitor ExitCodeHandler::thread_terminate_monitor_; |
| static char* SafeStrNCpy(char* dest, const char* src, size_t n) { |
| @@ -491,3 +528,8 @@ bool Process::Kill(intptr_t id) { |
| void Process::Exit(intptr_t id) { |
| ProcessInfoList::RemoveProcess(id); |
| } |
| + |
| + |
| +void Process::TerminateExitCodeHandler() { |
| + ExitCodeHandler::TerminateExitCodeThread(); |
| +} |