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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler.cc
diff --git a/runtime/bin/eventhandler.cc b/runtime/bin/eventhandler.cc
index d4d8a285bc40ffa5e74845fbe827fa7327ea61b3..6c431dbe915c883cb723dfad1c96f1e230c93ca0 100644
--- a/runtime/bin/eventhandler.cc
+++ b/runtime/bin/eventhandler.cc
@@ -62,17 +62,11 @@ void TimeoutQueue::UpdateTimeout(Dart_Port port, int64_t timeout) {
}
-/*
- * Returns the reference of the EventHandler stored in the native field.
- */
-static EventHandler* GetEventHandler(Dart_Handle handle) {
- ASSERT(event_handler != NULL);
- return event_handler;
-}
-
void EventHandler::Stop() {
+ MutexLocker locker(mutex_);
if (event_handler == NULL) return;
event_handler->Shutdown();
+ event_handler = NULL;
}
@@ -95,20 +89,22 @@ void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
*/
void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
Dart_EnterScope();
- Dart_Handle handle = Dart_GetNativeArgument(args, 0);
- EventHandler* event_handler = GetEventHandler(handle);
- Dart_Handle sender = Dart_GetNativeArgument(args, 1);
- intptr_t id = kInvalidId;
- if (Dart_IsNull(sender)) {
- id = kTimerId;
- } else {
- Socket::GetSocketIdNativeField(sender, &id);
+ MutexLocker locker(mutex_);
+ // Only send if the event handler is active.
+ if (event_handler) {
+ Dart_Handle sender = Dart_GetNativeArgument(args, 1);
+ intptr_t id = kInvalidId;
+ if (Dart_IsNull(sender)) {
+ id = kTimerId;
+ } else {
+ Socket::GetSocketIdNativeField(sender, &id);
+ }
+ Dart_Handle handle = Dart_GetNativeArgument(args, 2);
+ Dart_Port dart_port =
+ DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
+ int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
+ event_handler->SendData(id, dart_port, data);
kustermann 2013/07/17 08:58:03 As you/fschneider proposed, you could just do: ...
}
- handle = Dart_GetNativeArgument(args, 2);
- Dart_Port dart_port =
- DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
- int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
- event_handler->SendData(id, dart_port, data);
Dart_ExitScope();
}
« 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