Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
dart::MessageQueue Class Reference

#include <message.h>

Classes

class  Iterator
 

Public Member Functions

 MessageQueue ()
 
 ~MessageQueue ()
 
void Enqueue (std::unique_ptr< Message > msg, bool before_events)
 
std::unique_ptr< MessageDequeue ()
 
bool IsEmpty ()
 
void Clear ()
 
intptr_t Length () const
 
MessageFindMessageById (intptr_t id)
 
void PrintJSON (JSONStream *stream)
 

Detailed Description

Definition at line 159 of file message.h.

Constructor & Destructor Documentation

◆ MessageQueue()

dart::MessageQueue::MessageQueue ( )

Definition at line 87 of file message.cc.

87 {
88 head_ = nullptr;
89 tail_ = nullptr;
90}

◆ ~MessageQueue()

dart::MessageQueue::~MessageQueue ( )

Definition at line 92 of file message.cc.

92 {
93 // Ensure that all pending messages have been released.
94 Clear();
95 ASSERT(head_ == nullptr);
96}
#define ASSERT(E)

Member Function Documentation

◆ Clear()

void dart::MessageQueue::Clear ( )

Definition at line 158 of file message.cc.

158 {
159 std::unique_ptr<Message> cur(head_);
160 head_ = nullptr;
161 tail_ = nullptr;
162 while (cur != nullptr) {
163 std::unique_ptr<Message> next(cur->next_);
164 cur = std::move(next);
165 }
166}
static float next(float f)

◆ Dequeue()

std::unique_ptr< Message > dart::MessageQueue::Dequeue ( )

Definition at line 142 of file message.cc.

142 {
143 Message* result = head_;
144 if (result != nullptr) {
145 head_ = result->next_;
146 // The following update to tail_ is not strictly needed.
147 if (head_ == nullptr) {
148 tail_ = nullptr;
149 }
150#if defined(DEBUG)
151 result->next_ = result; // Make sure to trigger ASSERT in Enqueue.
152#endif // DEBUG
153 return std::unique_ptr<Message>(result);
154 }
155 return nullptr;
156}
GAsyncResult * result

◆ Enqueue()

void dart::MessageQueue::Enqueue ( std::unique_ptr< Message msg,
bool  before_events 
)

Definition at line 98 of file message.cc.

98 {
99 // TODO(mdempsky): Use unique_ptr internally?
100 Message* msg = msg0.release();
101
102 // Make sure messages are not reused.
103 ASSERT(msg->next_ == nullptr);
104 if (head_ == nullptr) {
105 // Only element in the queue.
106 ASSERT(tail_ == nullptr);
107 head_ = msg;
108 tail_ = msg;
109 } else {
110 ASSERT(tail_ != nullptr);
111 if (!before_events) {
112 // Append at the tail.
113 tail_->next_ = msg;
114 tail_ = msg;
115 } else {
116 ASSERT(msg->dest_port() == Message::kIllegalPort);
117 if (head_->dest_port() != Message::kIllegalPort) {
118 msg->next_ = head_;
119 head_ = msg;
120 } else {
121 Message* cur = head_;
122 while (cur->next_ != nullptr) {
123 if (cur->next_->dest_port() != Message::kIllegalPort) {
124 // Splice in the new message at the break.
125 msg->next_ = cur->next_;
126 cur->next_ = msg;
127 return;
128 }
129 cur = cur->next_;
130 }
131 // All pending messages are isolate library control messages. Append at
132 // the tail.
133 ASSERT(tail_ == cur);
135 tail_->next_ = msg;
136 tail_ = msg;
137 }
138 }
139 }
140}
Dart_Port dest_port() const
Definition: message.h:76
static const Dart_Port kIllegalPort
Definition: message.h:47

◆ FindMessageById()

Message * dart::MessageQueue::FindMessageById ( intptr_t  id)

Definition at line 201 of file message.cc.

201 {
202 MessageQueue::Iterator it(this);
203 while (it.HasNext()) {
204 Message* current = it.Next();
205 ASSERT(current != nullptr);
206 if (current->Id() == id) {
207 return current;
208 }
209 }
210 return nullptr;
211}

◆ IsEmpty()

bool dart::MessageQueue::IsEmpty ( )
inline

Definition at line 170 of file message.h.

170{ return head_ == nullptr; }

◆ Length()

intptr_t dart::MessageQueue::Length ( ) const

Definition at line 191 of file message.cc.

191 {
192 MessageQueue::Iterator it(this);
193 intptr_t length = 0;
194 while (it.HasNext()) {
195 it.Next();
196 length++;
197 }
198 return length;
199}
size_t length

◆ PrintJSON()

void dart::MessageQueue::PrintJSON ( JSONStream stream)

Definition at line 213 of file message.cc.

213 {
214#ifndef PRODUCT
215 JSONArray messages(stream);
216
217 Object& msg_handler = Object::Handle();
218
219 MessageQueue::Iterator it(this);
220 intptr_t depth = 0;
221 while (it.HasNext()) {
222 Message* current = it.Next();
223 JSONObject message(&messages);
224 message.AddProperty("type", "Message");
225 message.AddPropertyF("name", "Isolate Message (%" Px ")", current->Id());
226 message.AddPropertyF("messageObjectId", "messages/%" Px "", current->Id());
227 message.AddProperty("size", current->Size());
228 message.AddProperty("index", depth++);
229 message.AddPropertyF("_destinationPort", "%" Pd64 "",
230 static_cast<int64_t>(current->dest_port()));
231 message.AddProperty("_priority",
232 Message::PriorityAsString(current->priority()));
233 // TODO(johnmccutchan): Move port -> handler map out of Dart and into the
234 // VM, that way we can lookup the handler without invoking Dart code.
235 msg_handler = DartLibraryCalls::LookupHandler(current->dest_port());
236 if (msg_handler.IsClosure()) {
237 // Grab function from closure.
238 msg_handler = Closure::Cast(msg_handler).function();
239 }
240 if (msg_handler.IsFunction()) {
241 const Function& function = Function::Cast(msg_handler);
242 message.AddProperty("handler", function);
243
244 const Script& script = Script::Handle(function.script());
245 if (!script.IsNull()) {
246 message.AddLocation(script, function.token_pos(),
247 function.end_token_pos());
248 }
249 }
250 }
251#endif // !PRODUCT
252}
static ObjectPtr LookupHandler(Dart_Port port_id)
Definition: dart_entry.cc:664
static const char * PriorityAsString(Priority priority)
Definition: message.cc:73
static Object & Handle()
Definition: object.h:407
Dart_NativeFunction function
Definition: fuchsia.cc:51
Win32Message message
#define Px
Definition: globals.h:410
#define Pd64
Definition: globals.h:416

The documentation for this class was generated from the following files: