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 "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
9 | 9 |
10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 timeout_port_ = 0; | 899 timeout_port_ = 0; |
900 shutdown_ = false; | 900 shutdown_ = false; |
901 } | 901 } |
902 | 902 |
903 | 903 |
904 EventHandlerImplementation::~EventHandlerImplementation() { | 904 EventHandlerImplementation::~EventHandlerImplementation() { |
905 CloseHandle(completion_port_); | 905 CloseHandle(completion_port_); |
906 } | 906 } |
907 | 907 |
908 | 908 |
909 DWORD EventHandlerImplementation::GetTimeout() { | 909 int64_t EventHandlerImplementation::GetTimeout() { |
910 if (timeout_ == kInfinityTimeout) { | 910 if (timeout_ == kInfinityTimeout) { |
911 return kInfinityTimeout; | 911 return kInfinityTimeout; |
912 } | 912 } |
913 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 913 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
914 return (millis < 0) ? 0 : millis; | 914 return (millis < 0) ? 0 : millis; |
915 } | 915 } |
916 | 916 |
917 | 917 |
918 void EventHandlerImplementation::SendData(intptr_t id, | 918 void EventHandlerImplementation::SendData(intptr_t id, |
919 Dart_Port dart_port, | 919 Dart_Port dart_port, |
920 int64_t data) { | 920 int64_t data) { |
921 InterruptMessage* msg = new InterruptMessage; | 921 InterruptMessage* msg = new InterruptMessage; |
922 msg->id = id; | 922 msg->id = id; |
923 msg->dart_port = dart_port; | 923 msg->dart_port = dart_port; |
924 msg->data = data; | 924 msg->data = data; |
925 BOOL ok = PostQueuedCompletionStatus( | 925 BOOL ok = PostQueuedCompletionStatus( |
926 completion_port_, 0, NULL, reinterpret_cast<OVERLAPPED*>(msg)); | 926 completion_port_, 0, NULL, reinterpret_cast<OVERLAPPED*>(msg)); |
927 if (!ok) { | 927 if (!ok) { |
928 FATAL("PostQueuedCompletionStatus failed"); | 928 FATAL("PostQueuedCompletionStatus failed"); |
929 } | 929 } |
930 } | 930 } |
931 | 931 |
932 | 932 |
933 void EventHandlerImplementation::EventHandlerEntry(uword args) { | 933 void EventHandlerImplementation::EventHandlerEntry(uword args) { |
934 EventHandler* handler = reinterpret_cast<EventHandler*>(args); | 934 EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
935 EventHandlerImplementation* handler_impl = &handler->delegate_; | 935 EventHandlerImplementation* handler_impl = &handler->delegate_; |
936 ASSERT(handler_impl != NULL); | 936 ASSERT(handler_impl != NULL); |
937 while (!handler_impl->shutdown_) { | 937 while (!handler_impl->shutdown_) { |
938 DWORD bytes; | 938 DWORD bytes; |
939 ULONG_PTR key; | 939 ULONG_PTR key; |
940 OVERLAPPED* overlapped; | 940 OVERLAPPED* overlapped; |
941 intptr_t millis = handler_impl->GetTimeout(); | 941 int64_t millis = handler_impl->GetTimeout(); |
| 942 ASSERT(millis == kInfinityTimeout || millis >= 0); |
| 943 if (millis > kMaxInt32) millis = kMaxInt32; |
| 944 ASSERT(sizeof(int32_t) == sizeof(DWORD)); |
942 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(), | 945 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(), |
943 &bytes, | 946 &bytes, |
944 &key, | 947 &key, |
945 &overlapped, | 948 &overlapped, |
946 millis); | 949 static_cast<DWORD>(millis)); |
947 if (!ok && overlapped == NULL) { | 950 if (!ok && overlapped == NULL) { |
948 if (GetLastError() == ERROR_ABANDONED_WAIT_0) { | 951 if (GetLastError() == ERROR_ABANDONED_WAIT_0) { |
949 // The completion port should never be closed. | 952 // The completion port should never be closed. |
950 Log::Print("Completion port closed\n"); | 953 Log::Print("Completion port closed\n"); |
951 UNREACHABLE(); | 954 UNREACHABLE(); |
952 } else { | 955 } else { |
953 // Timeout is signalled by false result and NULL in overlapped. | 956 // Timeout is signalled by false result and NULL in overlapped. |
954 handler_impl->HandleTimeout(); | 957 handler_impl->HandleTimeout(); |
955 } | 958 } |
956 } else if (!ok) { | 959 } else if (!ok) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 | 1001 |
999 | 1002 |
1000 void EventHandlerImplementation::Shutdown() { | 1003 void EventHandlerImplementation::Shutdown() { |
1001 SendData(kShutdownId, 0, 0); | 1004 SendData(kShutdownId, 0, 0); |
1002 } | 1005 } |
1003 | 1006 |
1004 } // namespace bin | 1007 } // namespace bin |
1005 } // namespace dart | 1008 } // namespace dart |
1006 | 1009 |
1007 #endif // defined(TARGET_OS_WINDOWS) | 1010 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |