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

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: 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 current = current->next(); 60 current = current->next();
61 } 61 }
62 } 62 }
63 63
64 64
65 /* 65 /*
66 * Returns the reference of the EventHandler stored in the native field. 66 * Returns the reference of the EventHandler stored in the native field.
67 */ 67 */
68 static EventHandler* GetEventHandler(Dart_Handle handle) { 68 static EventHandler* GetEventHandler(Dart_Handle handle) {
69 ASSERT(event_handler != NULL); 69 MutexLocker locker(mutex_);
Florian Schneider 2013/07/17 08:38:09 Why is a mutex needed here?
Anders Johnsen 2013/07/17 08:59:49 Done.
70 return event_handler; 70 return event_handler;
71 } 71 }
72 72
73
73 void EventHandler::Stop() { 74 void EventHandler::Stop() {
75 MutexLocker locker(mutex_);
74 if (event_handler == NULL) return; 76 if (event_handler == NULL) return;
75 event_handler->Shutdown(); 77 EventHandler* e = event_handler;
78 event_handler = NULL;
79 e->Shutdown();
76 } 80 }
77 81
78 82
79 /* 83 /*
80 * Starts the EventHandler thread and stores its reference in the dart 84 * Starts the EventHandler thread and stores its reference in the dart
81 * EventHandler object. args[0] holds the reference to the dart EventHandler 85 * EventHandler object. args[0] holds the reference to the dart EventHandler
82 * object. 86 * object.
83 */ 87 */
84 void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) { 88 void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
85 MutexLocker locker(mutex_); 89 MutexLocker locker(mutex_);
86 if (event_handler != NULL) return; 90 if (event_handler != NULL) return;
87 event_handler = EventHandler::Start(); 91 event_handler = EventHandler::Start();
88 } 92 }
89 93
90 94
91 /* 95 /*
92 * Send data to the EventHandler thread to register for a given instance 96 * 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] 97 * args[1] a ReceivePort args[2] with a notification event args[3]. args[0]
94 * holds the reference to the dart EventHandler object. 98 * holds the reference to the dart EventHandler object.
95 */ 99 */
96 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { 100 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
97 Dart_EnterScope(); 101 Dart_EnterScope();
98 Dart_Handle handle = Dart_GetNativeArgument(args, 0); 102 Dart_Handle handle = Dart_GetNativeArgument(args, 0);
99 EventHandler* event_handler = GetEventHandler(handle); 103 EventHandler* event_handler = GetEventHandler(handle);
Florian Schneider 2013/07/17 08:38:09 Maybe not such a good idea to have a local variabl
Anders Johnsen 2013/07/17 08:59:49 Done.
100 Dart_Handle sender = Dart_GetNativeArgument(args, 1); 104 // Only send if the event handler is active.
101 intptr_t id = kInvalidId; 105 if (event_handler) {
kustermann 2013/07/17 08:49:46 Please add a comment when event_handler is NULL an
Anders Johnsen 2013/07/17 08:59:49 Done.
102 if (Dart_IsNull(sender)) { 106 Dart_Handle sender = Dart_GetNativeArgument(args, 1);
103 id = kTimerId; 107 intptr_t id = kInvalidId;
104 } else { 108 if (Dart_IsNull(sender)) {
105 Socket::GetSocketIdNativeField(sender, &id); 109 id = kTimerId;
110 } else {
111 Socket::GetSocketIdNativeField(sender, &id);
112 }
113 handle = Dart_GetNativeArgument(args, 2);
114 Dart_Port dart_port =
115 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
116 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
117 event_handler->SendData(id, dart_port, data);
106 } 118 }
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(); 119 Dart_ExitScope();
113 } 120 }
114 121
115 } // namespace bin 122 } // namespace bin
116 } // namespace dart 123 } // 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