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

Side by Side Diff: runtime/vm/message.h

Issue 9924015: Use the ThreadPool for all isolates and native ports. Previously, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 VM_MESSAGE_H_ 5 #ifndef VM_MESSAGE_H_
6 #define VM_MESSAGE_H_ 6 #define VM_MESSAGE_H_
7 7
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 9
10 // Duplicated from dart_api.h to avoid including the whole header. 10 // Duplicated from dart_api.h to avoid including the whole header.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 }; 60 };
61 61
62 // There is a message queue per isolate. 62 // There is a message queue per isolate.
63 class MessageQueue { 63 class MessageQueue {
64 public: 64 public:
65 MessageQueue(); 65 MessageQueue();
66 ~MessageQueue(); 66 ~MessageQueue();
67 67
68 void Enqueue(Message* msg); 68 void Enqueue(Message* msg);
69 69
70 // Gets the next message from the message queue, possibly blocking 70 // Gets the next message from the message queue or NULL if no
71 // if no message is available. 'millis' is a timeout in 71 // message is available.
72 // milliseconds. If 'millis' is 0, then this means to block 72 Message* Dequeue();
73 // indefinitely. May block if no message is available. May return
74 // NULL even if 'millis' is 0 due to spurious wakeups.
75 Message* Dequeue(int64_t millis);
76
77 // Gets the next message from the message queue if available. Will
78 // not block.
79 Message* DequeueNoWait();
80
81 // Gets the next message of the specified priority or greater from
82 // the message queue if available. Will not block.
83 Message* DequeueNoWaitWithPriority(Message::Priority min_priority);
84 73
85 void Flush(Dart_Port port); 74 void Flush(Dart_Port port);
86 void FlushAll(); 75 void FlushAll();
87 76
88 private: 77 private:
89 friend class MessageQueueTestPeer; 78 friend class MessageQueueTestPeer;
90 79
91 Message* DequeueNoWaitHoldsLock(Message::Priority min_priority); 80 Message* head_;
92 81 Message* tail_;
93 Monitor monitor_;
94 Message* head_[Message::kNumPriorities];
95 Message* tail_[Message::kNumPriorities];
96 82
97 DISALLOW_COPY_AND_ASSIGN(MessageQueue); 83 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
98 }; 84 };
99 85
100 // A MessageHandler is an entity capable of accepting messages.
101 class MessageHandler {
102 protected:
103 MessageHandler();
104
105 // Allows subclasses to provide custom message notification.
106 virtual void MessageNotify(Message::Priority priority);
107
108 public:
109 virtual ~MessageHandler();
110
111 // Allow subclasses to provide a handler name.
112 virtual const char* name() const;
113
114 #if defined(DEBUG)
115 // Check that it is safe to access this message handler.
116 //
117 // For example, if this MessageHandler is an isolate, then it is
118 // only safe to access it when the MessageHandler is the current
119 // isolate.
120 virtual void CheckAccess();
121 #endif
122
123 void PostMessage(Message* message);
124 void ClosePort(Dart_Port port);
125 void CloseAllPorts();
126
127 // A message handler tracks how many live ports it has.
128 bool HasLivePorts() const { return live_ports_ > 0; }
129 void increment_live_ports() {
130 #if defined(DEBUG)
131 CheckAccess();
132 #endif
133 live_ports_++;
134 }
135 void decrement_live_ports() {
136 #if defined(DEBUG)
137 CheckAccess();
138 #endif
139 live_ports_--;
140 }
141
142 // Returns true if the handler is owned by the PortMap.
143 //
144 // This is used to delete handlers when their last live port is closed.
145 virtual bool OwnedByPortMap() const { return false; }
146
147 MessageQueue* queue() const { return queue_; }
148
149 private:
150 intptr_t live_ports_;
151 MessageQueue* queue_;
152 };
153
154 } // namespace dart 86 } // namespace dart
155 87
156 #endif // VM_MESSAGE_H_ 88 #endif // VM_MESSAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698