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

Side by Side Diff: runtime/bin/eventhandler.h

Issue 17851004: One event handler for all isolates (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unused line. 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 | runtime/bin/eventhandler.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 #ifndef BIN_EVENTHANDLER_H_ 5 #ifndef BIN_EVENTHANDLER_H_
6 #define BIN_EVENTHANDLER_H_ 6 #define BIN_EVENTHANDLER_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/isolate_data.h" 9 #include "bin/isolate_data.h"
10 10
11 namespace dart { 11 namespace dart {
12 namespace bin { 12 namespace bin {
13 13
14 // Flags used to provide information and actions to the eventhandler 14 // Flags used to provide information and actions to the eventhandler
15 // when sending a message about a file descriptor. These flags should 15 // when sending a message about a file descriptor. These flags should
16 // be kept in sync with the constants in socket_impl.dart. For more 16 // be kept in sync with the constants in socket_impl.dart. For more
17 // information see the comments in socket_impl.dart 17 // information see the comments in socket_impl.dart
18 enum MessageFlags { 18 enum MessageFlags {
19 kInEvent = 0, 19 kInEvent = 0,
20 kOutEvent = 1, 20 kOutEvent = 1,
21 kErrorEvent = 2, 21 kErrorEvent = 2,
22 kCloseEvent = 3, 22 kCloseEvent = 3,
23 kCloseCommand = 8, 23 kCloseCommand = 8,
24 kShutdownReadCommand = 9, 24 kShutdownReadCommand = 9,
25 kShutdownWriteCommand = 10, 25 kShutdownWriteCommand = 10,
26 kListeningSocket = 16, 26 kListeningSocket = 16,
27 kPipe = 17, 27 kPipe = 17,
28 }; 28 };
29 29
30
31 class TimeoutQueue {
32 private:
33 class Timeout {
34 public:
35 Timeout(Dart_Port port, int64_t timeout, Timeout* next)
36 : port_(port), timeout_(timeout), next_(next) {}
37
38 Dart_Port port() const { return port_; }
39
40 int64_t timeout() const { return timeout_; }
41 void set_timeout(int64_t timeout) {
42 ASSERT(timeout >= 0);
43 timeout_ = timeout;
44 }
45
46 Timeout* next() const { return next_; }
47 void set_next(Timeout* next) {
48 next_ = next;
49 }
50
51 private:
52 Dart_Port port_;
53 int64_t timeout_;
54 Timeout* next_;
55 };
56
57 public:
58 TimeoutQueue() : next_timeout_(NULL), timeouts_(NULL) {}
59
60 ~TimeoutQueue() {
61 while (HasTimeout()) RemoveCurrent();
62 }
63
64 bool HasTimeout() const { return next_timeout_ != NULL; }
65
66 int64_t CurrentTimeout() const {
67 return next_timeout_->timeout();
68 }
69
70 Dart_Port CurrentPort() const {
71 return next_timeout_->port();
72 }
73
74 void RemoveCurrent() {
75 UpdateTimeout(CurrentPort(), -1);
76 }
77
78 void UpdateTimeout(Dart_Port port, int64_t timeout);
79
80 private:
81 Timeout* next_timeout_;
82 Timeout* timeouts_;
83 };
84
30 } // namespace bin 85 } // namespace bin
31 } // namespace dart 86 } // namespace dart
32 87
33 // The event handler delegation class is OS specific. 88 // The event handler delegation class is OS specific.
34 #if defined(TARGET_OS_ANDROID) 89 #if defined(TARGET_OS_ANDROID)
35 #include "bin/eventhandler_android.h" 90 #include "bin/eventhandler_android.h"
36 #elif defined(TARGET_OS_LINUX) 91 #elif defined(TARGET_OS_LINUX)
37 #include "bin/eventhandler_linux.h" 92 #include "bin/eventhandler_linux.h"
38 #elif defined(TARGET_OS_MACOS) 93 #elif defined(TARGET_OS_MACOS)
39 #include "bin/eventhandler_macos.h" 94 #include "bin/eventhandler_macos.h"
(...skipping 12 matching lines...) Expand all
52 delegate_.SendData(id, dart_port, data); 107 delegate_.SendData(id, dart_port, data);
53 } 108 }
54 109
55 void Shutdown() { 110 void Shutdown() {
56 delegate_.Shutdown(); 111 delegate_.Shutdown();
57 } 112 }
58 113
59 static EventHandler* Start() { 114 static EventHandler* Start() {
60 EventHandler* handler = new EventHandler(); 115 EventHandler* handler = new EventHandler();
61 handler->delegate_.Start(handler); 116 handler->delegate_.Start(handler);
62 IsolateData* isolate_data =
63 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
64 isolate_data->event_handler = handler;
65 return handler; 117 return handler;
66 } 118 }
67 119
120 static void Stop();
121
68 private: 122 private:
69 friend class EventHandlerImplementation; 123 friend class EventHandlerImplementation;
70 EventHandlerImplementation delegate_; 124 EventHandlerImplementation delegate_;
71 }; 125 };
72 126
73 } // namespace bin 127 } // namespace bin
74 } // namespace dart 128 } // namespace dart
75 129
76 #endif // BIN_EVENTHANDLER_H_ 130 #endif // BIN_EVENTHANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698