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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/message.h
diff --git a/runtime/vm/message.h b/runtime/vm/message.h
index 42a1eb1e1a353a1bb681b27ba33b56aa29301d57..cd3fb8ba919674f00bb51a8865f5eb8112b833c3 100644
--- a/runtime/vm/message.h
+++ b/runtime/vm/message.h
@@ -37,6 +37,12 @@ class Message {
kDelayedIsolateLibOOBMsg = 3,
} OOBMsgTag;
+ typedef enum {
+ kDataType = 0,
+ kIntegerType = 1,
+ kNumTypes = 2,
+ } MessageType;
+
// A port number which is never used.
static const Dart_Port kIllegalPort = 0;
@@ -51,20 +57,47 @@ class Message {
: next_(NULL),
dest_port_(dest_port),
delivery_failure_port_(delivery_failure_port),
- data_(data),
- len_(len),
- priority_(priority) {
+ priority_(priority),
+ type_(kDataType) {
+ ASSERT((priority == kNormalPriority) ||
+ (delivery_failure_port == kIllegalPort));
+ data_.buffer.data = data;
+ data_.buffer.len = len;
+ }
+ Message(Dart_Port dest_port,
+ intptr_t data,
+ Priority priority,
+ Dart_Port delivery_failure_port = kIllegalPort)
+ : next_(NULL),
+ dest_port_(dest_port),
+ delivery_failure_port_(delivery_failure_port),
+ priority_(priority),
+ type_(kIntegerType) {
ASSERT((priority == kNormalPriority) ||
(delivery_failure_port == kIllegalPort));
+ data_.integer = data;
}
~Message() {
ASSERT(delivery_failure_port_ == kIllegalPort);
- free(data_);
+ if (type_ == kDataType) {
+ free(data_.buffer.data);
+ }
}
Dart_Port dest_port() const { return dest_port_; }
- uint8_t* data() const { return data_; }
- intptr_t len() const { return len_; }
+ MessageType type() const { return type_; }
+ uint8_t* data() const {
+ ASSERT(type_ == kDataType);
+ return data_.buffer.data;
+ }
+ intptr_t len() const {
+ ASSERT(type_ == kDataType);
+ return data_.buffer.len;
+ }
+ intptr_t integer() const {
+ ASSERT(type_ == kIntegerType);
+ return data_.integer;
+ }
Priority priority() const { return priority_; }
bool IsOOB() const { return priority_ == Message::kOOBPriority; }
@@ -81,9 +114,15 @@ class Message {
Message* next_;
Dart_Port dest_port_;
Dart_Port delivery_failure_port_;
- uint8_t* data_;
- intptr_t len_;
+ union {
+ struct {
+ uint8_t* data;
+ intptr_t len;
+ } buffer; // Avtive when type_ == kDataType.
+ 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
+ } data_;
Priority priority_;
+ MessageType type_;
DISALLOW_COPY_AND_ASSIGN(Message);
};
« 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