Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Unified Diff: runtime/bin/process_macos.cc

Issue 9315037: Wait for exit-code thread to terminate before terminating main. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comment. Added updated test binaries. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_macos.cc
diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
index 3ecf98eaae04b9388f4e85f003d7ff54ed33e114..b5ac36c08b5c8564bcba3f3c2154eceb932d7a3b 100644
--- a/runtime/bin/process_macos.cc
+++ b/runtime/bin/process_macos.cc
@@ -135,7 +135,36 @@ 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:
+ static const uint8_t kThreadTerminateByte = 1;
+
// GetProcessExitCodes is called on a separate thread when a SIGCHLD
// signal is received to retrieve the exit codes and post them to
// dart.
@@ -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();
+}
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698