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

Unified Diff: runtime/bin/process_macos.cc

Issue 9307003: Changes to the process implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Close the wake-up handle at the right time. 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
Index: runtime/bin/process_macos.cc
diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
index 3ecf98eaae04b9388f4e85f003d7ff54ed33e114..959318e2cebe6f87ff51d79b261e979e302cd4bf 100644
--- a/runtime/bin/process_macos.cc
+++ b/runtime/bin/process_macos.cc
@@ -24,6 +24,12 @@
class ProcessInfo {
public:
ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { }
+ ~ProcessInfo() {
+ int closed = TEMP_FAILURE_RETRY(close(fd_));
+ if (closed != 0) {
+ FATAL("Failed to close process exit code pipe");
+ }
+ }
pid_t pid() { return pid_; }
intptr_t fd() { return fd_; }
ProcessInfo* next() { return next_; }
@@ -100,6 +106,8 @@ dart::Mutex ProcessInfoList::mutex_;
// event loop.
class ExitCodeHandler {
public:
+ static const char kTerminateByte = 1;
+
// Ensure that the ExitCodeHandler has been initialized.
static bool EnsureInitialized() {
// Multiple isolates could be starting processes at the same
@@ -135,6 +143,18 @@ class ExitCodeHandler {
return sig_chld_fds_[1];
}
+ static void Terminate() {
+ MutexLocker locker(&mutex_);
+ if (!initialized_) {
+ return;
+ }
+ char data = ExitCodeHandler::kTerminateByte;
+ ssize_t result = TEMP_FAILURE_RETRY(write(WakeUpFd(), &data, 1));
+ if (result < 1) {
+ perror("Failed to write to wake-up fd in SIGCHLD handler");
+ }
+ }
+
private:
// GetProcessExitCodes is called on a separate thread when a SIGCHLD
// signal is received to retrieve the exit codes and post them to
@@ -154,13 +174,13 @@ class ExitCodeHandler {
}
intptr_t exit_code_fd = ProcessInfoList::LookupProcessExitFd(pid);
if (exit_code_fd != 0) {
- int message[3] = { pid, exit_code, negative };
+ int message[2] = { exit_code, negative };
ssize_t result =
FDUtils::WriteToBlocking(exit_code_fd, &message, sizeof(message));
if (result != sizeof(message) && errno != EPIPE) {
perror("ExitHandler notification failed");
}
- TEMP_FAILURE_RETRY(close(exit_code_fd));
+ ProcessInfoList::RemoveProcess(pid);
}
}
}
@@ -187,6 +207,10 @@ class ExitCodeHandler {
if (read_bytes < 1) {
perror("Failed to read from wake-up fd in exit-code handler");
}
+ // Check if the ExitCodeHandler has been terminated.
+ if (data == ExitCodeHandler::kTerminateByte) {
+ return;
+ }
// Get the exit code from all processes that have died.
GetProcessExitCodes();
}
@@ -487,6 +511,6 @@ bool Process::Kill(intptr_t id) {
}
-void Process::Exit(intptr_t id) {
- ProcessInfoList::RemoveProcess(id);
+void Process::TerminateExitCodeHandler() {
+ ExitCodeHandler::Terminate();
}

Powered by Google App Engine
This is Rietveld 408576698