| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <process.h> | 5 #include <process.h> |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
| 10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // started from Dart. | 67 // started from Dart. |
| 68 class ProcessInfoList { | 68 class ProcessInfoList { |
| 69 public: | 69 public: |
| 70 static void AddProcess(DWORD pid, HANDLE handle, HANDLE pipe) { | 70 static void AddProcess(DWORD pid, HANDLE handle, HANDLE pipe) { |
| 71 // Create a wait operation for the process handle to extract | 71 // Create a wait operation for the process handle to extract |
| 72 // the exit code. | 72 // the exit code. |
| 73 HANDLE wait_handle = INVALID_HANDLE_VALUE; | 73 HANDLE wait_handle = INVALID_HANDLE_VALUE; |
| 74 BOOL success = RegisterWaitForSingleObject( | 74 BOOL success = RegisterWaitForSingleObject( |
| 75 &wait_handle, | 75 &wait_handle, |
| 76 handle, | 76 handle, |
| 77 reinterpret_cast<WAITORTIMERCALLBACK>(ExitCodeCallback), | 77 &ExitCodeCallback, |
| 78 reinterpret_cast<void*>(pid), | 78 reinterpret_cast<void*>(pid), |
| 79 INFINITE, | 79 INFINITE, |
| 80 WT_EXECUTEONLYONCE); | 80 WT_EXECUTEONLYONCE); |
| 81 if (!success) { | 81 if (!success) { |
| 82 FATAL("Failed to register exit code wait operation."); | 82 FATAL("Failed to register exit code wait operation."); |
| 83 } | 83 } |
| 84 ProcessInfo* info = new ProcessInfo(pid, handle, wait_handle, pipe); | 84 ProcessInfo* info = new ProcessInfo(pid, handle, wait_handle, pipe); |
| 85 // Now mutate the process list under the mutex. | 85 // Now mutate the process list under the mutex. |
| 86 MutexLocker locker(&mutex_); | 86 MutexLocker locker(&mutex_); |
| 87 info->set_next(active_processes_); | 87 info->set_next(active_processes_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 prev = current; | 123 prev = current; |
| 124 current = current->next(); | 124 current = current->next(); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 // Callback called when an exit code is available from one of the | 129 // Callback called when an exit code is available from one of the |
| 130 // processes in the list. | 130 // processes in the list. |
| 131 static void ExitCodeCallback(void* data, bool timed_out) { | 131 static void CALLBACK ExitCodeCallback(PVOID data, BOOLEAN timed_out) { |
| 132 if (timed_out) return; | 132 if (timed_out) return; |
| 133 DWORD pid = reinterpret_cast<DWORD>(data); | 133 DWORD pid = reinterpret_cast<DWORD>(data); |
| 134 HANDLE handle; | 134 HANDLE handle; |
| 135 HANDLE wait_handle; | 135 HANDLE wait_handle; |
| 136 HANDLE exit_pipe; | 136 HANDLE exit_pipe; |
| 137 bool success = LookupProcess(pid, &handle, &wait_handle, &exit_pipe); | 137 bool success = LookupProcess(pid, &handle, &wait_handle, &exit_pipe); |
| 138 if (!success) { | 138 if (!success) { |
| 139 FATAL("Failed to lookup process in list of active processes"); | 139 FATAL("Failed to lookup process in list of active processes"); |
| 140 } | 140 } |
| 141 // Unregister the event in a non-blocking way. | 141 // Unregister the event in a non-blocking way. |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 519 |
| 520 | 520 |
| 521 void Process::TerminateExitCodeHandler() { | 521 void Process::TerminateExitCodeHandler() { |
| 522 // Nothing needs to be done on Windows. | 522 // Nothing needs to be done on Windows. |
| 523 } | 523 } |
| 524 | 524 |
| 525 | 525 |
| 526 intptr_t Process::CurrentProcessId() { | 526 intptr_t Process::CurrentProcessId() { |
| 527 return static_cast<intptr_t>(GetCurrentProcessId()); | 527 return static_cast<intptr_t>(GetCurrentProcessId()); |
| 528 } | 528 } |
| OLD | NEW |