Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: runtime/bin/eventhandler_win.cc

Issue 9141005: Change the thread interface in runtime/platform and use it starting all threads (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from asiva@ Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, 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 "bin/eventhandler.h"
6
5 #include <process.h> 7 #include <process.h>
6 #include <winsock2.h> 8 #include <winsock2.h>
7 #include <ws2tcpip.h> 9 #include <ws2tcpip.h>
8 #include <mswsock.h> 10 #include <mswsock.h>
9 11
10 #include "bin/builtin.h" 12 #include "bin/builtin.h"
11 #include "bin/eventhandler.h"
12 #include "bin/socket.h" 13 #include "bin/socket.h"
13 14
14 15
15 static const int kInfinityTimeout = -1; 16 static const int kInfinityTimeout = -1;
16 17
17 18
18 int64_t GetCurrentTimeMilliseconds() { 19 int64_t GetCurrentTimeMilliseconds() {
19 static const int64_t kTimeEpoc = 116444736000000000LL; 20 static const int64_t kTimeEpoc = 116444736000000000LL;
20 21
21 // Although win32 uses 64-bit integers for representing timestamps, 22 // Although win32 uses 64-bit integers for representing timestamps,
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 msg->dart_port = dart_port; 817 msg->dart_port = dart_port;
817 msg->data = data; 818 msg->data = data;
818 BOOL ok = PostQueuedCompletionStatus( 819 BOOL ok = PostQueuedCompletionStatus(
819 completion_port_, 0, NULL, reinterpret_cast<OVERLAPPED*>(msg)); 820 completion_port_, 0, NULL, reinterpret_cast<OVERLAPPED*>(msg));
820 if (!ok) { 821 if (!ok) {
821 FATAL("PostQueuedCompletionStatus failed"); 822 FATAL("PostQueuedCompletionStatus failed");
822 } 823 }
823 } 824 }
824 825
825 826
826 static unsigned int __stdcall EventHandlerThread(void* args) { 827 static void EventHandlerThread(uword args) {
827 EventHandlerImplementation* handler = 828 EventHandlerImplementation* handler =
828 reinterpret_cast<EventHandlerImplementation*>(args); 829 reinterpret_cast<EventHandlerImplementation*>(args);
830 ASSERT(handler != NULL);
829 while (true) { 831 while (true) {
830 DWORD bytes; 832 DWORD bytes;
831 ULONG_PTR key; 833 ULONG_PTR key;
832 OVERLAPPED* overlapped; 834 OVERLAPPED* overlapped;
833 intptr_t millis = handler->GetTimeout(); 835 intptr_t millis = handler->GetTimeout();
834 BOOL ok = GetQueuedCompletionStatus(handler->completion_port(), 836 BOOL ok = GetQueuedCompletionStatus(handler->completion_port(),
835 &bytes, 837 &bytes,
836 &key, 838 &key,
837 &overlapped, 839 &overlapped,
838 millis); 840 millis);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 handler->HandleInterrupt(msg); 872 handler->HandleInterrupt(msg);
871 delete msg; 873 delete msg;
872 } else { 874 } else {
873 handler->HandleIOCompletion(bytes, key, overlapped); 875 handler->HandleIOCompletion(bytes, key, overlapped);
874 } 876 }
875 } 877 }
876 } 878 }
877 879
878 880
879 void EventHandlerImplementation::StartEventHandler() { 881 void EventHandlerImplementation::StartEventHandler() {
880 uint32_t tid; 882 int result = dart::Thread::Start(EventHandlerThread,
881 uintptr_t thread_handle = 883 reinterpret_cast<uword>(this));
882 _beginthreadex(NULL, 32 * 1024, EventHandlerThread, this, 0, &tid); 884 if (result != 0) {
883 if (thread_handle == -1) { 885 FATAL1("Failed to start event handler thread %d", result);
884 FATAL("Failed to start event handler thread");
885 } 886 }
886 887
887 // Initialize Winsock32 888 // Initialize Winsock32
888 if (!Socket::Initialize()) { 889 if (!Socket::Initialize()) {
889 FATAL("Failed to initialized Windows sockets"); 890 FATAL("Failed to initialized Windows sockets");
890 } 891 }
891 } 892 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698