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

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

Issue 1499853004: Adds a special case for sending an int over a port with the native API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Cleanup Created 5 years 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
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 "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"
11 #include "vm/raw_object.h"
11 12
12 // Duplicated from dart_api.h to avoid including the whole header. 13 // Duplicated from dart_api.h to avoid including the whole header.
13 typedef int64_t Dart_Port; 14 typedef int64_t Dart_Port;
14 15
15 namespace dart { 16 namespace dart {
16 17
17 class JSONStream; 18 class JSONStream;
18 19
19 class Message { 20 class Message {
20 public: 21 public:
(...skipping 29 matching lines...) Expand all
50 Dart_Port delivery_failure_port = kIllegalPort) 51 Dart_Port delivery_failure_port = kIllegalPort)
51 : next_(NULL), 52 : next_(NULL),
52 dest_port_(dest_port), 53 dest_port_(dest_port),
53 delivery_failure_port_(delivery_failure_port), 54 delivery_failure_port_(delivery_failure_port),
54 data_(data), 55 data_(data),
55 len_(len), 56 len_(len),
56 priority_(priority) { 57 priority_(priority) {
57 ASSERT((priority == kNormalPriority) || 58 ASSERT((priority == kNormalPriority) ||
58 (delivery_failure_port == kIllegalPort)); 59 (delivery_failure_port == kIllegalPort));
59 } 60 }
61
62 // Message objects can also carry RawObject pointers for Smis and objects in
63 // the VM heap. This is indicated by setting the len_ field to 0.
64 Message(Dart_Port dest_port,
65 RawObject* raw_obj,
66 Priority priority,
67 Dart_Port delivery_failure_port = kIllegalPort)
68 : next_(NULL),
69 dest_port_(dest_port),
70 delivery_failure_port_(delivery_failure_port),
71 data_(reinterpret_cast<uint8_t*>(raw_obj)),
72 len_(0),
73 priority_(priority) {
74 ASSERT(!raw_obj->IsHeapObject() || raw_obj->IsVMHeapObject());
75 ASSERT((priority == kNormalPriority) ||
76 (delivery_failure_port == kIllegalPort));
77 }
60 ~Message() { 78 ~Message() {
61 ASSERT(delivery_failure_port_ == kIllegalPort); 79 ASSERT(delivery_failure_port_ == kIllegalPort);
62 free(data_); 80 if (len_ > 0) {
81 free(data_);
82 }
63 } 83 }
64 84
65 Dart_Port dest_port() const { return dest_port_; } 85 Dart_Port dest_port() const { return dest_port_; }
66 uint8_t* data() const { return data_; } 86 uint8_t* data() const {
67 intptr_t len() const { return len_; } 87 ASSERT(len_ > 0);
88 return data_;
89 }
90 intptr_t len() const {
91 return len_;
92 }
93 RawObject* raw_obj() const {
94 ASSERT(len_ == 0);
95 return reinterpret_cast<RawObject*>(data_);
96 }
68 Priority priority() const { return priority_; } 97 Priority priority() const { return priority_; }
69 98
70 bool IsOOB() const { return priority_ == Message::kOOBPriority; } 99 bool IsOOB() const { return priority_ == Message::kOOBPriority; }
100 bool IsRaw() const { return len_ == 0; }
71 101
72 bool RedirectToDeliveryFailurePort(); 102 bool RedirectToDeliveryFailurePort();
73 103
74 intptr_t Id() const; 104 intptr_t Id() const;
75 105
76 static const char* PriorityAsString(Priority priority); 106 static const char* PriorityAsString(Priority priority);
77 107
78 private: 108 private:
79 friend class MessageQueue; 109 friend class MessageQueue;
80 110
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 private: 163 private:
134 Message* head_; 164 Message* head_;
135 Message* tail_; 165 Message* tail_;
136 166
137 DISALLOW_COPY_AND_ASSIGN(MessageQueue); 167 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
138 }; 168 };
139 169
140 } // namespace dart 170 } // namespace dart
141 171
142 #endif // VM_MESSAGE_H_ 172 #endif // VM_MESSAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698