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 "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. |
11 typedef int64_t Dart_Port; | 11 typedef int64_t Dart_Port; |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 class Message { | 15 class Message { |
16 public: | 16 public: |
17 typedef enum { | 17 typedef enum { |
18 kNormalPriority = 0, // Deliver message when idle. | 18 kNormalPriority = 0, // Deliver message when idle. |
19 kOOBPriority = 1, // Deliver message asap. | 19 kOOBPriority = 1, // Deliver message asap. |
20 | 20 |
21 // Iteration. | 21 // Iteration. |
22 kFirstPriority = 0, | 22 kFirstPriority = 0, |
23 kNumPriorities = 2, | 23 kNumPriorities = 2, |
24 } Priority; | 24 } Priority; |
25 | 25 |
| 26 // Values defining the type of OOB messages. OOB messages can only be |
| 27 // fixed length arrays where the first element is a Smi with one of the |
| 28 // valid values below. |
| 29 typedef enum { |
| 30 kIllegalOOB = 0, |
| 31 kServiceOOBMsg = 1, |
| 32 kIsolateLibOOBMsg = 2 |
| 33 } OOBMsgTag; |
| 34 |
26 // A port number which is never used. | 35 // A port number which is never used. |
27 static const Dart_Port kIllegalPort = 0; | 36 static const Dart_Port kIllegalPort = 0; |
28 | 37 |
29 // A new message to be sent between two isolates. The data handed to this | 38 // A new message to be sent between two isolates. The data handed to this |
30 // message will be disposed by calling free() once the message object is | 39 // message will be disposed by calling free() once the message object is |
31 // being destructed (after delivery or when the receiving port is closed). | 40 // being destructed (after delivery or when the receiving port is closed). |
32 Message(Dart_Port dest_port, uint8_t* data, intptr_t len, Priority priority) | 41 Message(Dart_Port dest_port, |
| 42 uint8_t* data, |
| 43 intptr_t len, |
| 44 Priority priority, |
| 45 Dart_Port delivery_failure_port = kIllegalPort) |
33 : next_(NULL), | 46 : next_(NULL), |
34 dest_port_(dest_port), | 47 dest_port_(dest_port), |
| 48 delivery_failure_port_(delivery_failure_port), |
35 data_(data), | 49 data_(data), |
36 len_(len), | 50 len_(len), |
37 priority_(priority) { | 51 priority_(priority) { |
38 ASSERT(dest_port != kIllegalPort); | 52 ASSERT(dest_port != kIllegalPort); |
| 53 ASSERT((priority == kNormalPriority) || |
| 54 (delivery_failure_port == kIllegalPort)); |
39 } | 55 } |
40 ~Message() { | 56 ~Message() { |
| 57 ASSERT(delivery_failure_port_ == kIllegalPort); |
41 free(data_); | 58 free(data_); |
42 } | 59 } |
43 | 60 |
44 Dart_Port dest_port() const { return dest_port_; } | 61 Dart_Port dest_port() const { return dest_port_; } |
45 uint8_t* data() const { return data_; } | 62 uint8_t* data() const { return data_; } |
46 intptr_t len() const { return len_; } | 63 intptr_t len() const { return len_; } |
47 Priority priority() const { return priority_; } | 64 Priority priority() const { return priority_; } |
48 | 65 |
49 bool IsOOB() const { return priority_ == Message::kOOBPriority; } | 66 bool IsOOB() const { return priority_ == Message::kOOBPriority; } |
50 | 67 |
| 68 bool RedirectToDeliveryFailurePort(); |
| 69 |
51 private: | 70 private: |
52 friend class MessageQueue; | 71 friend class MessageQueue; |
53 | 72 |
54 Message* next_; | 73 Message* next_; |
55 Dart_Port dest_port_; | 74 Dart_Port dest_port_; |
| 75 Dart_Port delivery_failure_port_; |
56 uint8_t* data_; | 76 uint8_t* data_; |
57 intptr_t len_; | 77 intptr_t len_; |
58 Priority priority_; | 78 Priority priority_; |
59 | 79 |
60 DISALLOW_COPY_AND_ASSIGN(Message); | 80 DISALLOW_COPY_AND_ASSIGN(Message); |
61 }; | 81 }; |
62 | 82 |
63 // There is a message queue per isolate. | 83 // There is a message queue per isolate. |
64 class MessageQueue { | 84 class MessageQueue { |
65 public: | 85 public: |
(...skipping 14 matching lines...) Expand all Loading... |
80 | 100 |
81 Message* head_; | 101 Message* head_; |
82 Message* tail_; | 102 Message* tail_; |
83 | 103 |
84 DISALLOW_COPY_AND_ASSIGN(MessageQueue); | 104 DISALLOW_COPY_AND_ASSIGN(MessageQueue); |
85 }; | 105 }; |
86 | 106 |
87 } // namespace dart | 107 } // namespace dart |
88 | 108 |
89 #endif // VM_MESSAGE_H_ | 109 #endif // VM_MESSAGE_H_ |
OLD | NEW |