OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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(TARGET_OS_WINDOWS) | 8 #if defined(TARGET_OS_WINDOWS) |
9 | 9 |
10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 void Handle::WaitForReadThreadStarted() { | 182 void Handle::WaitForReadThreadStarted() { |
183 MonitorLocker ml(monitor_); | 183 MonitorLocker ml(monitor_); |
184 while (read_thread_starting_) { | 184 while (read_thread_starting_) { |
185 ml.Wait(); | 185 ml.Wait(); |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 void Handle::WaitForReadThreadFinished() { | 190 void Handle::WaitForReadThreadFinished() { |
191 // Join the Reader thread if there is one. | 191 MonitorLocker ml(monitor_); |
192 ThreadId to_join = Thread::kInvalidThreadId; | 192 if (read_thread_id_ != Thread::kInvalidThreadId) { |
193 { | 193 while (!read_thread_finished_) { |
194 MonitorLocker ml(monitor_); | 194 ml.Wait(); |
195 if (read_thread_id_ != Thread::kInvalidThreadId) { | |
196 while (!read_thread_finished_) { | |
197 ml.Wait(); | |
198 } | |
199 read_thread_finished_ = false; | |
200 to_join = read_thread_id_; | |
201 read_thread_id_ = Thread::kInvalidThreadId; | |
202 } | 195 } |
203 } | 196 read_thread_finished_ = false; |
204 if (to_join != Thread::kInvalidThreadId) { | 197 read_thread_id_ = Thread::kInvalidThreadId; |
205 Thread::Join(to_join); | |
206 } | 198 } |
207 } | 199 } |
208 | 200 |
209 | 201 |
210 void Handle::ReadComplete(OverlappedBuffer* buffer) { | 202 void Handle::ReadComplete(OverlappedBuffer* buffer) { |
211 WaitForReadThreadStarted(); | 203 WaitForReadThreadStarted(); |
212 { | 204 { |
213 MonitorLocker ml(monitor_); | 205 MonitorLocker ml(monitor_); |
214 // Currently only one outstanding read at the time. | 206 // Currently only one outstanding read at the time. |
215 ASSERT(pending_read_ == buffer); | 207 ASSERT(pending_read_ == buffer); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 | 824 |
833 | 825 |
834 void StdHandle::DoClose() { | 826 void StdHandle::DoClose() { |
835 MonitorLocker ml(monitor_); | 827 MonitorLocker ml(monitor_); |
836 if (write_thread_exists_) { | 828 if (write_thread_exists_) { |
837 write_thread_running_ = false; | 829 write_thread_running_ = false; |
838 ml.Notify(); | 830 ml.Notify(); |
839 while (write_thread_exists_) { | 831 while (write_thread_exists_) { |
840 ml.Wait(Monitor::kNoTimeout); | 832 ml.Wait(Monitor::kNoTimeout); |
841 } | 833 } |
842 Thread::Join(thread_id_); | |
843 } | 834 } |
844 Handle::DoClose(); | 835 Handle::DoClose(); |
845 } | 836 } |
846 | 837 |
847 | 838 |
848 bool ClientSocket::LoadDisconnectEx() { | 839 bool ClientSocket::LoadDisconnectEx() { |
849 // Load the DisconnectEx function into memory using WSAIoctl. | 840 // Load the DisconnectEx function into memory using WSAIoctl. |
850 GUID guid_disconnect_ex = WSAID_DISCONNECTEX; | 841 GUID guid_disconnect_ex = WSAID_DISCONNECTEX; |
851 DWORD bytes; | 842 DWORD bytes; |
852 int status = WSAIoctl(socket(), | 843 int status = WSAIoctl(socket(), |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 completion_port_ = | 1360 completion_port_ = |
1370 CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1); | 1361 CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1); |
1371 if (completion_port_ == NULL) { | 1362 if (completion_port_ == NULL) { |
1372 FATAL("Completion port creation failed"); | 1363 FATAL("Completion port creation failed"); |
1373 } | 1364 } |
1374 shutdown_ = false; | 1365 shutdown_ = false; |
1375 } | 1366 } |
1376 | 1367 |
1377 | 1368 |
1378 EventHandlerImplementation::~EventHandlerImplementation() { | 1369 EventHandlerImplementation::~EventHandlerImplementation() { |
1379 Thread::Join(handler_thread_id_); | |
1380 delete startup_monitor_; | 1370 delete startup_monitor_; |
1381 CloseHandle(completion_port_); | 1371 CloseHandle(completion_port_); |
1382 } | 1372 } |
1383 | 1373 |
1384 | 1374 |
1385 int64_t EventHandlerImplementation::GetTimeout() { | 1375 int64_t EventHandlerImplementation::GetTimeout() { |
1386 if (!timeout_queue_.HasTimeout()) { | 1376 if (!timeout_queue_.HasTimeout()) { |
1387 return kInfinityTimeout; | 1377 return kInfinityTimeout; |
1388 } | 1378 } |
1389 int64_t millis = timeout_queue_.CurrentTimeout() - | 1379 int64_t millis = timeout_queue_.CurrentTimeout() - |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 void EventHandlerImplementation::Shutdown() { | 1492 void EventHandlerImplementation::Shutdown() { |
1503 SendData(kShutdownId, 0, 0); | 1493 SendData(kShutdownId, 0, 0); |
1504 } | 1494 } |
1505 | 1495 |
1506 } // namespace bin | 1496 } // namespace bin |
1507 } // namespace dart | 1497 } // namespace dart |
1508 | 1498 |
1509 #endif // defined(TARGET_OS_WINDOWS) | 1499 #endif // defined(TARGET_OS_WINDOWS) |
1510 | 1500 |
1511 #endif // !defined(DART_IO_DISABLED) | 1501 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |