| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include <process.h> // NOLINT | 8 #include <process.h> // NOLINT |
| 9 | 9 |
| 10 #include "bin/builtin.h" | 10 #include "bin/builtin.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // Singly-linked list of ProcessInfo objects for all active processes | 74 // Singly-linked list of ProcessInfo objects for all active processes |
| 75 // started from Dart. | 75 // started from Dart. |
| 76 class ProcessInfoList { | 76 class ProcessInfoList { |
| 77 public: | 77 public: |
| 78 static void AddProcess(DWORD pid, HANDLE handle, HANDLE pipe) { | 78 static void AddProcess(DWORD pid, HANDLE handle, HANDLE pipe) { |
| 79 // Register a callback to extract the exit code, when the process | 79 // Register a callback to extract the exit code, when the process |
| 80 // is signaled. The callback runs in a independent thread from the OS pool. | 80 // is signaled. The callback runs in a independent thread from the OS pool. |
| 81 // Because the callback depends on the process list containing | 81 // Because the callback depends on the process list containing |
| 82 // the process, lock the mutex until the process is added to the list. | 82 // the process, lock the mutex until the process is added to the list. |
| 83 MutexLocker locker(&mutex_); | 83 MutexLocker locker(mutex_); |
| 84 HANDLE wait_handle = INVALID_HANDLE_VALUE; | 84 HANDLE wait_handle = INVALID_HANDLE_VALUE; |
| 85 BOOL success = RegisterWaitForSingleObject( | 85 BOOL success = RegisterWaitForSingleObject( |
| 86 &wait_handle, | 86 &wait_handle, |
| 87 handle, | 87 handle, |
| 88 &ExitCodeCallback, | 88 &ExitCodeCallback, |
| 89 reinterpret_cast<void*>(pid), | 89 reinterpret_cast<void*>(pid), |
| 90 INFINITE, | 90 INFINITE, |
| 91 WT_EXECUTEONLYONCE); | 91 WT_EXECUTEONLYONCE); |
| 92 if (!success) { | 92 if (!success) { |
| 93 FATAL("Failed to register exit code wait operation."); | 93 FATAL("Failed to register exit code wait operation."); |
| 94 } | 94 } |
| 95 ProcessInfo* info = new ProcessInfo(pid, handle, wait_handle, pipe); | 95 ProcessInfo* info = new ProcessInfo(pid, handle, wait_handle, pipe); |
| 96 // Mutate the process list under the mutex. | 96 // Mutate the process list under the mutex. |
| 97 info->set_next(active_processes_); | 97 info->set_next(active_processes_); |
| 98 active_processes_ = info; | 98 active_processes_ = info; |
| 99 } | 99 } |
| 100 | 100 |
| 101 static bool LookupProcess(DWORD pid, | 101 static bool LookupProcess(DWORD pid, |
| 102 HANDLE* handle, | 102 HANDLE* handle, |
| 103 HANDLE* wait_handle, | 103 HANDLE* wait_handle, |
| 104 HANDLE* pipe) { | 104 HANDLE* pipe) { |
| 105 MutexLocker locker(&mutex_); | 105 MutexLocker locker(mutex_); |
| 106 ProcessInfo* current = active_processes_; | 106 ProcessInfo* current = active_processes_; |
| 107 while (current != NULL) { | 107 while (current != NULL) { |
| 108 if (current->pid() == pid) { | 108 if (current->pid() == pid) { |
| 109 *handle = current->process_handle(); | 109 *handle = current->process_handle(); |
| 110 *wait_handle = current->wait_handle(); | 110 *wait_handle = current->wait_handle(); |
| 111 *pipe = current->exit_pipe(); | 111 *pipe = current->exit_pipe(); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 current = current->next(); | 114 current = current->next(); |
| 115 } | 115 } |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 static void RemoveProcess(DWORD pid) { | 119 static void RemoveProcess(DWORD pid) { |
| 120 MutexLocker locker(&mutex_); | 120 MutexLocker locker(mutex_); |
| 121 ProcessInfo* prev = NULL; | 121 ProcessInfo* prev = NULL; |
| 122 ProcessInfo* current = active_processes_; | 122 ProcessInfo* current = active_processes_; |
| 123 while (current != NULL) { | 123 while (current != NULL) { |
| 124 if (current->pid() == pid) { | 124 if (current->pid() == pid) { |
| 125 if (prev == NULL) { | 125 if (prev == NULL) { |
| 126 active_processes_ = current->next(); | 126 active_processes_ = current->next(); |
| 127 } else { | 127 } else { |
| 128 prev->set_next(current->next()); | 128 prev->set_next(current->next()); |
| 129 } | 129 } |
| 130 delete current; | 130 delete current; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 // Remove the process from the list of active processes. | 180 // Remove the process from the list of active processes. |
| 181 RemoveProcess(pid); | 181 RemoveProcess(pid); |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Linked list of ProcessInfo objects for all active processes | 184 // Linked list of ProcessInfo objects for all active processes |
| 185 // started from Dart code. | 185 // started from Dart code. |
| 186 static ProcessInfo* active_processes_; | 186 static ProcessInfo* active_processes_; |
| 187 // Mutex protecting all accesses to the linked list of active | 187 // Mutex protecting all accesses to the linked list of active |
| 188 // processes. | 188 // processes. |
| 189 static dart::Mutex mutex_; | 189 static dart::Mutex* mutex_; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 | 192 |
| 193 ProcessInfo* ProcessInfoList::active_processes_ = NULL; | 193 ProcessInfo* ProcessInfoList::active_processes_ = NULL; |
| 194 dart::Mutex ProcessInfoList::mutex_; | 194 dart::Mutex* ProcessInfoList::mutex_ = new dart::Mutex(); |
| 195 | 195 |
| 196 | 196 |
| 197 // Types of pipes to create. | 197 // Types of pipes to create. |
| 198 enum NamedPipeType { | 198 enum NamedPipeType { |
| 199 kInheritRead, | 199 kInheritRead, |
| 200 kInheritWrite, | 200 kInheritWrite, |
| 201 kInheritNone | 201 kInheritNone |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 | 204 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 LPPROC_THREAD_ATTRIBUTE_LIST); | 336 LPPROC_THREAD_ATTRIBUTE_LIST); |
| 337 | 337 |
| 338 | 338 |
| 339 static InitProcThreadAttrListFn init_proc_thread_attr_list = NULL; | 339 static InitProcThreadAttrListFn init_proc_thread_attr_list = NULL; |
| 340 static UpdateProcThreadAttrFn update_proc_thread_attr = NULL; | 340 static UpdateProcThreadAttrFn update_proc_thread_attr = NULL; |
| 341 static DeleteProcThreadAttrListFn delete_proc_thread_attr_list = NULL; | 341 static DeleteProcThreadAttrListFn delete_proc_thread_attr_list = NULL; |
| 342 | 342 |
| 343 | 343 |
| 344 static bool EnsureInitialized() { | 344 static bool EnsureInitialized() { |
| 345 static bool load_attempted = false; | 345 static bool load_attempted = false; |
| 346 static dart::Mutex mutex; | 346 static dart::Mutex* mutex = new dart::Mutex(); |
| 347 HMODULE kernel32_module = GetModuleHandleW(L"kernel32.dll"); | 347 HMODULE kernel32_module = GetModuleHandleW(L"kernel32.dll"); |
| 348 if (!load_attempted) { | 348 if (!load_attempted) { |
| 349 MutexLocker locker(&mutex); | 349 MutexLocker locker(mutex); |
| 350 if (load_attempted) return delete_proc_thread_attr_list != NULL; | 350 if (load_attempted) return delete_proc_thread_attr_list != NULL; |
| 351 init_proc_thread_attr_list = reinterpret_cast<InitProcThreadAttrListFn>( | 351 init_proc_thread_attr_list = reinterpret_cast<InitProcThreadAttrListFn>( |
| 352 GetProcAddress(kernel32_module, "InitializeProcThreadAttributeList")); | 352 GetProcAddress(kernel32_module, "InitializeProcThreadAttributeList")); |
| 353 update_proc_thread_attr = | 353 update_proc_thread_attr = |
| 354 reinterpret_cast<UpdateProcThreadAttrFn>( | 354 reinterpret_cast<UpdateProcThreadAttrFn>( |
| 355 GetProcAddress(kernel32_module, "UpdateProcThreadAttribute")); | 355 GetProcAddress(kernel32_module, "UpdateProcThreadAttribute")); |
| 356 delete_proc_thread_attr_list = reinterpret_cast<DeleteProcThreadAttrListFn>( | 356 delete_proc_thread_attr_list = reinterpret_cast<DeleteProcThreadAttrListFn>( |
| 357 reinterpret_cast<DeleteProcThreadAttrListFn>( | 357 reinterpret_cast<DeleteProcThreadAttrListFn>( |
| 358 GetProcAddress(kernel32_module, "DeleteProcThreadAttributeList"))); | 358 GetProcAddress(kernel32_module, "DeleteProcThreadAttributeList"))); |
| 359 load_attempted = true; | 359 load_attempted = true; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 664 |
| 665 | 665 |
| 666 intptr_t Process::CurrentProcessId() { | 666 intptr_t Process::CurrentProcessId() { |
| 667 return static_cast<intptr_t>(GetCurrentProcessId()); | 667 return static_cast<intptr_t>(GetCurrentProcessId()); |
| 668 } | 668 } |
| 669 | 669 |
| 670 } // namespace bin | 670 } // namespace bin |
| 671 } // namespace dart | 671 } // namespace dart |
| 672 | 672 |
| 673 #endif // defined(TARGET_OS_WINDOWS) | 673 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |