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

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: Cleanup. 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 | runtime/bin/eventhandler_patch.dart » ('j') | 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..3cb5456ae5dd80f5dc72e93fef9b2314812ffb37 100644
--- a/runtime/bin/eventhandler.cc
+++ b/runtime/bin/eventhandler.cc
@@ -13,11 +13,12 @@
namespace dart {
namespace bin {
-static const int kNativeEventHandlerFieldIndex = 0;
static const intptr_t kTimerId = -1;
static const intptr_t kInvalidId = -2;
static EventHandler* event_handler = NULL;
+// TODO(ajohnsen): Consider removing mutex_ if we can enforce an invariant
+// that eventhandler is kept alive untill all isolates are closed.
static dart::Mutex* mutex_ = new dart::Mutex();
@@ -62,17 +63,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,8 +90,6 @@ 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)) {
@@ -104,11 +97,18 @@ void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
} else {
Socket::GetSocketIdNativeField(sender, &id);
}
- handle = Dart_GetNativeArgument(args, 2);
+ 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);
+ {
+ MutexLocker locker(mutex_);
+ // Only send if the event_handler is not NULL. This means that the handler
+ // shut down, and a message is send later on.
+ if (event_handler != NULL) {
+ event_handler->SendData(id, dart_port, data);
+ }
+ }
Dart_ExitScope();
}
« no previous file with comments | « no previous file | runtime/bin/eventhandler_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698