| 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(HOST_OS_WINDOWS) | 8 #if defined(HOST_OS_WINDOWS) |
| 9 | 9 |
| 10 #include "bin/process.h" | 10 #include "bin/process.h" |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 intptr_t Process::CurrentProcessId() { | 939 intptr_t Process::CurrentProcessId() { |
| 940 return static_cast<intptr_t>(GetCurrentProcessId()); | 940 return static_cast<intptr_t>(GetCurrentProcessId()); |
| 941 } | 941 } |
| 942 | 942 |
| 943 | 943 |
| 944 static SignalInfo* signal_handlers = NULL; | 944 static SignalInfo* signal_handlers = NULL; |
| 945 static Mutex* signal_mutex = new Mutex(); | 945 static Mutex* signal_mutex = new Mutex(); |
| 946 | 946 |
| 947 | 947 |
| 948 SignalInfo::~SignalInfo() { | 948 SignalInfo::~SignalInfo() { |
| 949 reinterpret_cast<FileHandle*>(fd_)->Close(); | 949 FileHandle* file_handle = reinterpret_cast<FileHandle*>(fd_); |
| 950 file_handle->Close(); |
| 951 file_handle->Release(); |
| 950 } | 952 } |
| 951 | 953 |
| 952 | 954 |
| 953 BOOL WINAPI SignalHandler(DWORD signal) { | 955 BOOL WINAPI SignalHandler(DWORD signal) { |
| 954 MutexLocker lock(signal_mutex); | 956 MutexLocker lock(signal_mutex); |
| 955 const SignalInfo* handler = signal_handlers; | 957 const SignalInfo* handler = signal_handlers; |
| 956 bool handled = false; | 958 bool handled = false; |
| 957 while (handler != NULL) { | 959 while (handler != NULL) { |
| 958 if (handler->signal() == signal) { | 960 if (handler->signal() == signal) { |
| 959 int value = 0; | 961 int value = 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 SetLastError(error_code); | 1000 SetLastError(error_code); |
| 999 return -1; | 1001 return -1; |
| 1000 } | 1002 } |
| 1001 MutexLocker lock(signal_mutex); | 1003 MutexLocker lock(signal_mutex); |
| 1002 FileHandle* write_handle = new FileHandle(fds[kWriteHandle]); | 1004 FileHandle* write_handle = new FileHandle(fds[kWriteHandle]); |
| 1003 write_handle->EnsureInitialized(EventHandler::delegate()); | 1005 write_handle->EnsureInitialized(EventHandler::delegate()); |
| 1004 intptr_t write_fd = reinterpret_cast<intptr_t>(write_handle); | 1006 intptr_t write_fd = reinterpret_cast<intptr_t>(write_handle); |
| 1005 if (signal_handlers == NULL) { | 1007 if (signal_handlers == NULL) { |
| 1006 if (SetConsoleCtrlHandler(SignalHandler, true) == 0) { | 1008 if (SetConsoleCtrlHandler(SignalHandler, true) == 0) { |
| 1007 int error_code = GetLastError(); | 1009 int error_code = GetLastError(); |
| 1008 delete write_handle; | 1010 // Since SetConsoleCtrlHandler failed, the IO completion port will |
| 1011 // never receive an event for this handle, and will therefore never |
| 1012 // release the reference Retained by EnsureInitialized(). So, we |
| 1013 // have to do a second Release() here. |
| 1014 write_handle->Release(); |
| 1015 write_handle->Release(); |
| 1009 CloseProcessPipe(fds); | 1016 CloseProcessPipe(fds); |
| 1010 SetLastError(error_code); | 1017 SetLastError(error_code); |
| 1011 return -1; | 1018 return -1; |
| 1012 } | 1019 } |
| 1013 } | 1020 } |
| 1014 signal_handlers = new SignalInfo(write_fd, signal, signal_handlers); | 1021 signal_handlers = new SignalInfo(write_fd, signal, signal_handlers); |
| 1015 return reinterpret_cast<intptr_t>(new FileHandle(fds[kReadHandle])); | 1022 return reinterpret_cast<intptr_t>(new FileHandle(fds[kReadHandle])); |
| 1016 } | 1023 } |
| 1017 | 1024 |
| 1018 | 1025 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1031 } | 1038 } |
| 1032 handler = handler->next(); | 1039 handler = handler->next(); |
| 1033 } | 1040 } |
| 1034 if (handler != NULL) { | 1041 if (handler != NULL) { |
| 1035 if (signal_handlers == handler) { | 1042 if (signal_handlers == handler) { |
| 1036 signal_handlers = handler->next(); | 1043 signal_handlers = handler->next(); |
| 1037 } | 1044 } |
| 1038 if (signal_handlers == NULL) { | 1045 if (signal_handlers == NULL) { |
| 1039 USE(SetConsoleCtrlHandler(SignalHandler, false)); | 1046 USE(SetConsoleCtrlHandler(SignalHandler, false)); |
| 1040 } | 1047 } |
| 1048 FileHandle* file_handle = reinterpret_cast<FileHandle*>(handler->fd()); |
| 1049 file_handle->Release(); |
| 1041 } | 1050 } |
| 1042 delete handler; | 1051 delete handler; |
| 1043 } | 1052 } |
| 1044 | 1053 |
| 1045 } // namespace bin | 1054 } // namespace bin |
| 1046 } // namespace dart | 1055 } // namespace dart |
| 1047 | 1056 |
| 1048 #endif // defined(HOST_OS_WINDOWS) | 1057 #endif // defined(HOST_OS_WINDOWS) |
| 1049 | 1058 |
| 1050 #endif // !defined(DART_IO_DISABLED) | 1059 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |