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

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

Issue 875403006: Wait for eventhandler to shut down before exiting (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove call to EventHandler::Stop() since VM doesn't support clean shutdown yet Created 5 years, 10 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 | « dart/runtime/bin/eventhandler.h ('k') | dart/runtime/bin/eventhandler_android.cc » ('j') | 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/lockers.h"
7 #include "bin/socket.h" 8 #include "bin/socket.h"
9 #include "bin/thread.h"
8 10
9 #include "include/dart_api.h" 11 #include "include/dart_api.h"
10 12
11 13
12 namespace dart { 14 namespace dart {
13 namespace bin { 15 namespace bin {
14 16
15 static const intptr_t kTimerId = -1; 17 static const intptr_t kTimerId = -1;
16 static const intptr_t kInvalidId = -2; 18 static const intptr_t kInvalidId = -2;
17 19
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 if (next_timeout_ == NULL || 52 if (next_timeout_ == NULL ||
51 current->timeout() < next_timeout_->timeout()) { 53 current->timeout() < next_timeout_->timeout()) {
52 next_timeout_ = current; 54 next_timeout_ = current;
53 } 55 }
54 current = current->next(); 56 current = current->next();
55 } 57 }
56 } 58 }
57 59
58 60
59 static EventHandler* event_handler = NULL; 61 static EventHandler* event_handler = NULL;
62 static Monitor *shutdown_monitor = NULL;
60 63
61 64
62 void EventHandler::Start() { 65 void EventHandler::Start() {
63 ASSERT(event_handler == NULL); 66 ASSERT(event_handler == NULL);
67 shutdown_monitor = new Monitor();
64 event_handler = new EventHandler(); 68 event_handler = new EventHandler();
65 event_handler->delegate_.Start(event_handler); 69 event_handler->delegate_.Start(event_handler);
66 } 70 }
67 71
68 72
69 void EventHandler::Stop() { 73 void EventHandler::NotifyShutdownDone() {
70 if (event_handler == NULL) return; 74 MonitorLocker ml(shutdown_monitor);
71 event_handler->delegate_.Shutdown(); 75 ml.Notify();
72 event_handler = NULL;
73 } 76 }
74 77
75 78
79 void EventHandler::Stop() {
80 if (event_handler == NULL) return;
81
82 // Wait until it has stopped.
83 {
84 MonitorLocker ml(shutdown_monitor);
85
86 // Signal to event handler that we want it to stop.
87 event_handler->delegate_.Shutdown();
88 ml.Wait(Monitor::kNoTimeout);
89 }
90
91 // Cleanup
92 delete event_handler;
93 event_handler = NULL;
94 delete shutdown_monitor;
95 shutdown_monitor = NULL;
96 }
97
98
76 EventHandlerImplementation* EventHandler::delegate() { 99 EventHandlerImplementation* EventHandler::delegate() {
77 if (event_handler == NULL) return NULL; 100 if (event_handler == NULL) return NULL;
78 return &event_handler->delegate_; 101 return &event_handler->delegate_;
79 } 102 }
80 103
81 104
82 /* 105 /*
83 * Send data to the EventHandler thread to register for a given instance 106 * Send data to the EventHandler thread to register for a given instance
84 * args[0] a ReceivePort args[1] with a notification event args[2]. 107 * args[0] a ReceivePort args[1] with a notification event args[2].
85 */ 108 */
(...skipping 13 matching lines...) Expand all
99 if (Dart_IsError(handle)) { 122 if (Dart_IsError(handle)) {
100 Dart_PropagateError(handle); 123 Dart_PropagateError(handle);
101 UNREACHABLE(); 124 UNREACHABLE();
102 } 125 }
103 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 126 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
104 event_handler->SendData(id, dart_port, data); 127 event_handler->SendData(id, dart_port, data);
105 } 128 }
106 129
107 } // namespace bin 130 } // namespace bin
108 } // namespace dart 131 } // namespace dart
OLDNEW
« no previous file with comments | « dart/runtime/bin/eventhandler.h ('k') | dart/runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698