| Index: runtime/bin/process_macos.cc
|
| diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
|
| index 3ecf98eaae04b9388f4e85f003d7ff54ed33e114..567f60cf888d118d19abee9e19c439bf58d08643 100644
|
| --- a/runtime/bin/process_macos.cc
|
| +++ b/runtime/bin/process_macos.cc
|
| @@ -100,6 +100,8 @@ dart::Mutex ProcessInfoList::mutex_;
|
| // event loop.
|
| class ExitCodeHandler {
|
| public:
|
| + static const uint8_t kThreadTerminateByte = 1;
|
| +
|
| // Ensure that the ExitCodeHandler has been initialized.
|
| static bool EnsureInitialized() {
|
| // Multiple isolates could be starting processes at the same
|
| @@ -135,6 +137,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
|
| @@ -187,6 +216,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();
|
| }
|
| @@ -196,12 +229,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) {
|
| @@ -490,3 +527,8 @@ bool Process::Kill(intptr_t id) {
|
| void Process::Exit(intptr_t id) {
|
| ProcessInfoList::RemoveProcess(id);
|
| }
|
| +
|
| +
|
| +void Process::TerminateExitCodeHandler() {
|
| + ExitCodeHandler::TerminateExitCodeThread();
|
| +}
|
|
|