Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 // Values defining the type of OOB messages. OOB messages can only be | 30 // Values defining the type of OOB messages. OOB messages can only be |
| 31 // fixed length arrays where the first element is a Smi with one of the | 31 // fixed length arrays where the first element is a Smi with one of the |
| 32 // valid values below. | 32 // valid values below. |
| 33 typedef enum { | 33 typedef enum { |
| 34 kIllegalOOB = 0, | 34 kIllegalOOB = 0, |
| 35 kServiceOOBMsg = 1, | 35 kServiceOOBMsg = 1, |
| 36 kIsolateLibOOBMsg = 2, | 36 kIsolateLibOOBMsg = 2, |
| 37 kDelayedIsolateLibOOBMsg = 3, | 37 kDelayedIsolateLibOOBMsg = 3, |
| 38 } OOBMsgTag; | 38 } OOBMsgTag; |
| 39 | 39 |
| 40 typedef enum { | |
| 41 kDataType = 0, | |
| 42 kIntegerType = 1, | |
| 43 kNumTypes = 2, | |
| 44 } MessageType; | |
| 45 | |
| 40 // A port number which is never used. | 46 // A port number which is never used. |
| 41 static const Dart_Port kIllegalPort = 0; | 47 static const Dart_Port kIllegalPort = 0; |
| 42 | 48 |
| 43 // A new message to be sent between two isolates. The data handed to this | 49 // A new message to be sent between two isolates. The data handed to this |
| 44 // message will be disposed by calling free() once the message object is | 50 // message will be disposed by calling free() once the message object is |
| 45 // being destructed (after delivery or when the receiving port is closed). | 51 // being destructed (after delivery or when the receiving port is closed). |
| 46 Message(Dart_Port dest_port, | 52 Message(Dart_Port dest_port, |
| 47 uint8_t* data, | 53 uint8_t* data, |
| 48 intptr_t len, | 54 intptr_t len, |
| 49 Priority priority, | 55 Priority priority, |
| 50 Dart_Port delivery_failure_port = kIllegalPort) | 56 Dart_Port delivery_failure_port = kIllegalPort) |
| 51 : next_(NULL), | 57 : next_(NULL), |
| 52 dest_port_(dest_port), | 58 dest_port_(dest_port), |
| 53 delivery_failure_port_(delivery_failure_port), | 59 delivery_failure_port_(delivery_failure_port), |
| 54 data_(data), | 60 priority_(priority), |
| 55 len_(len), | 61 type_(kDataType) { |
| 56 priority_(priority) { | |
| 57 ASSERT((priority == kNormalPriority) || | 62 ASSERT((priority == kNormalPriority) || |
| 58 (delivery_failure_port == kIllegalPort)); | 63 (delivery_failure_port == kIllegalPort)); |
| 64 data_.buffer.data = data; | |
| 65 data_.buffer.len = len; | |
| 66 } | |
| 67 Message(Dart_Port dest_port, | |
| 68 intptr_t data, | |
| 69 Priority priority, | |
| 70 Dart_Port delivery_failure_port = kIllegalPort) | |
| 71 : next_(NULL), | |
| 72 dest_port_(dest_port), | |
| 73 delivery_failure_port_(delivery_failure_port), | |
| 74 priority_(priority), | |
| 75 type_(kIntegerType) { | |
| 76 ASSERT((priority == kNormalPriority) || | |
| 77 (delivery_failure_port == kIllegalPort)); | |
| 78 data_.integer = data; | |
| 59 } | 79 } |
| 60 ~Message() { | 80 ~Message() { |
| 61 ASSERT(delivery_failure_port_ == kIllegalPort); | 81 ASSERT(delivery_failure_port_ == kIllegalPort); |
| 62 free(data_); | 82 if (type_ == kDataType) { |
| 83 free(data_.buffer.data); | |
| 84 } | |
| 63 } | 85 } |
| 64 | 86 |
| 65 Dart_Port dest_port() const { return dest_port_; } | 87 Dart_Port dest_port() const { return dest_port_; } |
| 66 uint8_t* data() const { return data_; } | 88 MessageType type() const { return type_; } |
| 67 intptr_t len() const { return len_; } | 89 uint8_t* data() const { |
| 90 ASSERT(type_ == kDataType); | |
| 91 return data_.buffer.data; | |
| 92 } | |
| 93 intptr_t len() const { | |
| 94 ASSERT(type_ == kDataType); | |
| 95 return data_.buffer.len; | |
| 96 } | |
| 97 intptr_t integer() const { | |
| 98 ASSERT(type_ == kIntegerType); | |
| 99 return data_.integer; | |
| 100 } | |
| 68 Priority priority() const { return priority_; } | 101 Priority priority() const { return priority_; } |
| 69 | 102 |
| 70 bool IsOOB() const { return priority_ == Message::kOOBPriority; } | 103 bool IsOOB() const { return priority_ == Message::kOOBPriority; } |
| 71 | 104 |
| 72 bool RedirectToDeliveryFailurePort(); | 105 bool RedirectToDeliveryFailurePort(); |
| 73 | 106 |
| 74 intptr_t Id() const; | 107 intptr_t Id() const; |
| 75 | 108 |
| 76 static const char* PriorityAsString(Priority priority); | 109 static const char* PriorityAsString(Priority priority); |
| 77 | 110 |
| 78 private: | 111 private: |
| 79 friend class MessageQueue; | 112 friend class MessageQueue; |
| 80 | 113 |
| 81 Message* next_; | 114 Message* next_; |
| 82 Dart_Port dest_port_; | 115 Dart_Port dest_port_; |
| 83 Dart_Port delivery_failure_port_; | 116 Dart_Port delivery_failure_port_; |
| 84 uint8_t* data_; | 117 union { |
| 85 intptr_t len_; | 118 struct { |
| 119 uint8_t* data; | |
| 120 intptr_t len; | |
| 121 } buffer; // Avtive when type_ == kDataType. | |
| 122 intptr_t integer; // Active when type_ == kIntegerType. | |
|
Ivan Posva
2015/12/08 08:25:55
Let's discuss this change in person to figure out
| |
| 123 } data_; | |
| 86 Priority priority_; | 124 Priority priority_; |
| 125 MessageType type_; | |
| 87 | 126 |
| 88 DISALLOW_COPY_AND_ASSIGN(Message); | 127 DISALLOW_COPY_AND_ASSIGN(Message); |
| 89 }; | 128 }; |
| 90 | 129 |
| 91 // There is a message queue per isolate. | 130 // There is a message queue per isolate. |
| 92 class MessageQueue { | 131 class MessageQueue { |
| 93 public: | 132 public: |
| 94 MessageQueue(); | 133 MessageQueue(); |
| 95 ~MessageQueue(); | 134 ~MessageQueue(); |
| 96 | 135 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 private: | 172 private: |
| 134 Message* head_; | 173 Message* head_; |
| 135 Message* tail_; | 174 Message* tail_; |
| 136 | 175 |
| 137 DISALLOW_COPY_AND_ASSIGN(MessageQueue); | 176 DISALLOW_COPY_AND_ASSIGN(MessageQueue); |
| 138 }; | 177 }; |
| 139 | 178 |
| 140 } // namespace dart | 179 } // namespace dart |
| 141 | 180 |
| 142 #endif // VM_MESSAGE_H_ | 181 #endif // VM_MESSAGE_H_ |
| OLD | NEW |