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

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

Issue 19546002: Clear EventHandler on Stop, to avoid future usages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Put SendData under Mutex lock as well. Created 7 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 while (current != NULL) { 55 while (current != NULL) {
56 if (next_timeout_ == NULL || 56 if (next_timeout_ == NULL ||
57 current->timeout() < next_timeout_->timeout()) { 57 current->timeout() < next_timeout_->timeout()) {
58 next_timeout_ = current; 58 next_timeout_ = current;
59 } 59 }
60 current = current->next(); 60 current = current->next();
61 } 61 }
62 } 62 }
63 63
64 64
65 /*
66 * Returns the reference of the EventHandler stored in the native field.
67 */
68 static EventHandler* GetEventHandler(Dart_Handle handle) {
69 ASSERT(event_handler != NULL);
70 return event_handler;
71 }
72
73 void EventHandler::Stop() { 65 void EventHandler::Stop() {
66 MutexLocker locker(mutex_);
74 if (event_handler == NULL) return; 67 if (event_handler == NULL) return;
75 event_handler->Shutdown(); 68 event_handler->Shutdown();
69 event_handler = NULL;
76 } 70 }
77 71
78 72
79 /* 73 /*
80 * Starts the EventHandler thread and stores its reference in the dart 74 * Starts the EventHandler thread and stores its reference in the dart
81 * EventHandler object. args[0] holds the reference to the dart EventHandler 75 * EventHandler object. args[0] holds the reference to the dart EventHandler
82 * object. 76 * object.
83 */ 77 */
84 void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) { 78 void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
85 MutexLocker locker(mutex_); 79 MutexLocker locker(mutex_);
86 if (event_handler != NULL) return; 80 if (event_handler != NULL) return;
87 event_handler = EventHandler::Start(); 81 event_handler = EventHandler::Start();
88 } 82 }
89 83
90 84
91 /* 85 /*
92 * 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
93 * 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]
94 * holds the reference to the dart EventHandler object. 88 * holds the reference to the dart EventHandler object.
95 */ 89 */
96 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { 90 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
97 Dart_EnterScope(); 91 Dart_EnterScope();
98 Dart_Handle handle = Dart_GetNativeArgument(args, 0); 92 MutexLocker locker(mutex_);
99 EventHandler* event_handler = GetEventHandler(handle); 93 // Only send if the event handler is active.
100 Dart_Handle sender = Dart_GetNativeArgument(args, 1); 94 if (event_handler) {
101 intptr_t id = kInvalidId; 95 Dart_Handle sender = Dart_GetNativeArgument(args, 1);
102 if (Dart_IsNull(sender)) { 96 intptr_t id = kInvalidId;
103 id = kTimerId; 97 if (Dart_IsNull(sender)) {
104 } else { 98 id = kTimerId;
105 Socket::GetSocketIdNativeField(sender, &id); 99 } else {
100 Socket::GetSocketIdNativeField(sender, &id);
101 }
102 Dart_Handle handle = Dart_GetNativeArgument(args, 2);
103 Dart_Port dart_port =
104 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
105 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
106 event_handler->SendData(id, dart_port, data);
kustermann 2013/07/17 08:58:03 As you/fschneider proposed, you could just do: ...
106 } 107 }
107 handle = Dart_GetNativeArgument(args, 2);
108 Dart_Port dart_port =
109 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
110 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
111 event_handler->SendData(id, dart_port, data);
112 Dart_ExitScope(); 108 Dart_ExitScope();
113 } 109 }
114 110
115 } // namespace bin 111 } // namespace bin
116 } // namespace dart 112 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698