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

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

Issue 22901017: Always initialize the EventHandler in the standalone. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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) 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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 #include "bin/eventhandler.h" 6 #include "bin/eventhandler.h"
7 #include "bin/socket.h" 7 #include "bin/socket.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 while (current != NULL) { 56 while (current != NULL) {
57 if (next_timeout_ == NULL || 57 if (next_timeout_ == NULL ||
58 current->timeout() < next_timeout_->timeout()) { 58 current->timeout() < next_timeout_->timeout()) {
59 next_timeout_ = current; 59 next_timeout_ = current;
60 } 60 }
61 current = current->next(); 61 current = current->next();
62 } 62 }
63 } 63 }
64 64
65 65
66 /*
67 * Starts the EventHandler thread.
68 */
69 void EventHandler::Start() {
Søren Gjesse 2013/08/21 13:52:05 You don't need the mutex here any more.
Anders Johnsen 2013/08/22 11:31:05 Done.
70 MutexLocker locker(mutex_);
Søren Gjesse 2013/08/21 13:52:05 Assert that event_handler_ is NULL.
Anders Johnsen 2013/08/22 11:31:05 Done.
71 if (event_handler != NULL) return;
72 event_handler = new EventHandler();
Søren Gjesse 2013/08/21 13:52:05 If we want we can still postpone the actual start
Anders Johnsen 2013/08/22 11:31:05 Yes, but I would like to avoid the extra check on
73 event_handler->delegate_.Start(event_handler);
74 }
75
76
66 void EventHandler::Stop() { 77 void EventHandler::Stop() {
67 MutexLocker locker(mutex_); 78 MutexLocker locker(mutex_);
68 if (event_handler == NULL) return; 79 if (event_handler == NULL) return;
69 event_handler->Shutdown(); 80 event_handler->Shutdown();
70 event_handler = NULL; 81 event_handler = NULL;
71 } 82 }
72 83
73 84
74 /*
75 * Starts the EventHandler thread and stores its reference in the dart
76 * EventHandler object. args[0] holds the reference to the dart EventHandler
77 * object.
78 */
79 void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
80 MutexLocker locker(mutex_);
81 if (event_handler != NULL) return;
82 event_handler = EventHandler::Start();
83 }
84
85
86 /* 85 /*
87 * Send data to the EventHandler thread to register for a given instance 86 * Send data to the EventHandler thread to register for a given instance
88 * args[1] a ReceivePort args[2] with a notification event args[3]. args[0] 87 * args[1] a ReceivePort args[2] with a notification event args[3]. args[0]
89 * holds the reference to the dart EventHandler object. 88 * holds the reference to the dart EventHandler object.
90 */ 89 */
91 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { 90 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
92 Dart_Handle sender = Dart_GetNativeArgument(args, 1); 91 Dart_Handle sender = Dart_GetNativeArgument(args, 0);
93 intptr_t id = kInvalidId; 92 intptr_t id = kInvalidId;
94 if (Dart_IsNull(sender)) { 93 if (Dart_IsNull(sender)) {
95 id = kTimerId; 94 id = kTimerId;
96 } else { 95 } else {
97 Socket::GetSocketIdNativeField(sender, &id); 96 Socket::GetSocketIdNativeField(sender, &id);
98 } 97 }
99 Dart_Handle handle = Dart_GetNativeArgument(args, 2); 98 Dart_Handle handle = Dart_GetNativeArgument(args, 1);
100 Dart_Port dart_port = 99 Dart_Port dart_port =
101 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName); 100 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
102 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 101 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
103 { 102 {
104 MutexLocker locker(mutex_); 103 MutexLocker locker(mutex_);
105 // Only send if the event_handler is not NULL. This means that the handler 104 // Only send if the event_handler is not NULL. This means that the handler
106 // shut down, and a message is send later on. 105 // shut down, and a message is send later on.
107 if (event_handler != NULL) { 106 if (event_handler != NULL) {
108 event_handler->SendData(id, dart_port, data); 107 event_handler->SendData(id, dart_port, data);
109 } 108 }
110 } 109 }
111 } 110 }
112 111
113 } // namespace bin 112 } // namespace bin
114 } // namespace dart 113 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698