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

Unified 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: Simplify impl and don't call Stop (other isolates may still be running). 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/eventhandler.cc
diff --git a/runtime/bin/eventhandler.cc b/runtime/bin/eventhandler.cc
index a07cf3d4192d753d472eb4e605f228110ec211a9..c25a2fac4e1b5d6fc221158e27283f8d54767d02 100644
--- a/runtime/bin/eventhandler.cc
+++ b/runtime/bin/eventhandler.cc
@@ -16,12 +16,6 @@ namespace bin {
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();
-
-
void TimeoutQueue::UpdateTimeout(Dart_Port port, int64_t timeout) {
// Find port if present.
Timeout* last = NULL;
@@ -63,51 +57,40 @@ void TimeoutQueue::UpdateTimeout(Dart_Port port, int64_t timeout) {
}
-void EventHandler::Stop() {
- MutexLocker locker(mutex_);
- if (event_handler == NULL) return;
- event_handler->Shutdown();
- event_handler = NULL;
+static EventHandler* event_handler = NULL;
+
+
+void EventHandler::Start() {
+ ASSERT(event_handler == NULL);
+ event_handler = new EventHandler();
+ event_handler->delegate_.Start(event_handler);
}
-/*
- * Starts the EventHandler thread and stores its reference in the dart
- * EventHandler object. args[0] holds the reference to the dart EventHandler
- * object.
- */
-void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
- MutexLocker locker(mutex_);
- if (event_handler != NULL) return;
- event_handler = EventHandler::Start();
+void EventHandler::Stop() {
+ if (event_handler == NULL) return;
+ event_handler->delegate_.Shutdown();
+ event_handler = NULL;
}
/*
* Send data to the EventHandler thread to register for a given instance
- * args[1] a ReceivePort args[2] with a notification event args[3]. args[0]
- * holds the reference to the dart EventHandler object.
+ * args[0] a ReceivePort args[1] with a notification event args[2].
*/
void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
- Dart_Handle sender = Dart_GetNativeArgument(args, 1);
+ Dart_Handle sender = Dart_GetNativeArgument(args, 0);
intptr_t id = kInvalidId;
if (Dart_IsNull(sender)) {
id = kTimerId;
} else {
Socket::GetSocketIdNativeField(sender, &id);
}
- Dart_Handle handle = Dart_GetNativeArgument(args, 2);
+ Dart_Handle handle = Dart_GetNativeArgument(args, 1);
Dart_Port dart_port =
DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName);
- int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
- {
- 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);
- }
- }
+ int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
+ event_handler->SendData(id, dart_port, data);
}
} // namespace bin

Powered by Google App Engine
This is Rietveld 408576698