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

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

Issue 9570046: Make the message queue private in the message handler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « runtime/vm/isolate.cc ('k') | runtime/vm/message.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) 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 if available.
71 // if no message is available. 'millis' is a timeout in 71 // Returns NULL if no 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 73
81 void Flush(Dart_Port port); 74 void Flush(Dart_Port port);
82 void FlushAll(); 75 void FlushAll();
83 76
84 private: 77 private:
85 friend class MessageQueueTestPeer; 78 friend class MessageQueueTestPeer;
86 79
87 Message* DequeueNoWaitHoldsLock();
88
89 Monitor monitor_;
90 Message* head_[Message::kNumPriorities]; 80 Message* head_[Message::kNumPriorities];
91 Message* tail_[Message::kNumPriorities]; 81 Message* tail_[Message::kNumPriorities];
92 82
93 DISALLOW_COPY_AND_ASSIGN(MessageQueue); 83 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
94 }; 84 };
95 85
96 // A MessageHandler is an entity capable of accepting messages. 86 // A MessageHandler is an entity capable of accepting messages.
97 class MessageHandler { 87 class MessageHandler {
98 protected: 88 protected:
99 MessageHandler();
100
101 // Allows subclasses to provide custom message notification. 89 // Allows subclasses to provide custom message notification.
102 virtual void MessageNotify(Message::Priority priority); 90 virtual void MessageNotify(Message::Priority priority);
103 91
104 public: 92 public:
93 MessageHandler();
105 virtual ~MessageHandler(); 94 virtual ~MessageHandler();
106 95
107 // Allow subclasses to provide a handler name. 96 // Allow subclasses to provide a handler name.
108 virtual const char* name() const; 97 virtual const char* name() const;
109 98
110 #if defined(DEBUG) 99 #if defined(DEBUG)
111 // Check that it is safe to access this message handler. 100 // Check that it is safe to access this message handler.
112 // 101 //
113 // For example, if this MessageHandler is an isolate, then it is 102 // For example, if this MessageHandler is an isolate, then it is
114 // only safe to access it when the MessageHandler is the current 103 // only safe to access it when the MessageHandler is the current
115 // isolate. 104 // isolate.
116 virtual void CheckAccess(); 105 virtual void CheckAccess();
117 #endif 106 #endif
118 107
119 void PostMessage(Message* message); 108 void PostMessage(Message* message);
120 void ClosePort(Dart_Port port); 109 void ClosePort(Dart_Port port);
121 void CloseAllPorts(); 110 void CloseAllPorts();
122 111
112 // Gets the next message from the message queue, possibly blocking
113 // if no message is available. 'millis' is a timeout in
114 // milliseconds. If 'millis' is 0, then this means to block
115 // indefinitely. May block if no message is available. May return
116 // NULL even if 'millis' is 0 due to spurious wakeups.
117 Message* Dequeue(int64_t millis);
118
119 // Gets the next message from the message queue if available. Will
120 // not block.
121 Message* DequeueNoWait();
122
123 // A message handler tracks how many live ports it has. 123 // A message handler tracks how many live ports it has.
124 bool HasLivePorts() const { return live_ports_ > 0; } 124 bool HasLivePorts() const { return live_ports_ > 0; }
125 void increment_live_ports() { 125 void increment_live_ports() {
126 #if defined(DEBUG) 126 #if defined(DEBUG)
127 CheckAccess(); 127 CheckAccess();
128 #endif 128 #endif
129 live_ports_++; 129 live_ports_++;
130 } 130 }
131 void decrement_live_ports() { 131 void decrement_live_ports() {
132 #if defined(DEBUG) 132 #if defined(DEBUG)
133 CheckAccess(); 133 CheckAccess();
134 #endif 134 #endif
135 live_ports_--; 135 live_ports_--;
136 } 136 }
137 137
138 // Returns true if the handler is owned by the PortMap. 138 // Returns true if the handler is owned by the PortMap.
139 // 139 //
140 // This is used to delete handlers when their last live port is closed. 140 // This is used to delete handlers when their last live port is closed.
141 virtual bool OwnedByPortMap() const { return false; } 141 virtual bool OwnedByPortMap() const { return false; }
142 142
143 MessageQueue* queue() const { return queue_; } 143 private:
144 friend class MessageHandlerTestPeer;
144 145
145 private: 146 Monitor monitor_;
146 intptr_t live_ports_; 147 intptr_t live_ports_;
147 MessageQueue* queue_; 148 MessageQueue* queue_;
148 }; 149 };
149 150
150 } // namespace dart 151 } // namespace dart
151 152
152 #endif // VM_MESSAGE_H_ 153 #endif // VM_MESSAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698