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

Side by Side Diff: mojo/edk/system/channel_endpoint_id.h

Issue 647553004: Mojo: Make room for remotely-allocated channel endpoint IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@channel_endpoint_id_tests
Patch Set: bah Created 6 years, 2 months 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
« no previous file with comments | « no previous file | mojo/edk/system/channel_endpoint_id.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
6 #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 6 #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <ostream> 11 #include <ostream>
12 12
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "mojo/edk/system/system_impl_export.h" 17 #include "mojo/edk/system/system_impl_export.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace system { 20 namespace system {
21 21
22 // ChannelEndpointId ----------------------------------------------------------- 22 // ChannelEndpointId -----------------------------------------------------------
23 23
24 class LocalChannelEndpointIdGenerator; 24 class LocalChannelEndpointIdGenerator;
25 FORWARD_DECLARE_TEST(LocalChannelEndpointIdGeneratorTest, WrapAround); 25 FORWARD_DECLARE_TEST(LocalChannelEndpointIdGeneratorTest, WrapAround);
26 26
27 // Represents an ID for an endpoint (i.e., one side of a message pipe) on a 27 // Represents an ID for an endpoint (i.e., one side of a message pipe) on a
28 // |Channel|. This class must be POD. 28 // |Channel|. This class must be POD.
29 //
30 // Note: The terminology "remotely allocated ID" is for destination IDs with
31 // respect to the receiver. I.e., a destination ID in a message is remotely
32 // allocated if the ID was allocated by the sender (i.e., the remote side with
33 // respect to the receiver). Conversely, a source ID is remotely allocated if it
34 // was allocated by the receiver.
29 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointId { 35 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointId {
30 public: 36 public:
31 ChannelEndpointId() : value_(0) {} 37 ChannelEndpointId() : value_(0) {}
32 ChannelEndpointId(const ChannelEndpointId& other) : value_(other.value_) {} 38 ChannelEndpointId(const ChannelEndpointId& other) : value_(other.value_) {}
33 39
34 // Returns the local ID to use for the first message pipe endpoint on a 40 // Returns the local ID to use for the first message pipe endpoint on a
35 // channel. 41 // channel.
36 static ChannelEndpointId GetBootstrap() { 42 static ChannelEndpointId GetBootstrap() {
37 ChannelEndpointId rv; 43 ChannelEndpointId rv;
38 rv.value_ = 1; 44 rv.value_ = 1;
39 return rv; 45 return rv;
40 } 46 }
41 47
42 bool operator==(const ChannelEndpointId& other) const { 48 bool operator==(const ChannelEndpointId& other) const {
43 return value_ == other.value_; 49 return value_ == other.value_;
44 } 50 }
45 bool operator!=(const ChannelEndpointId& other) const { 51 bool operator!=(const ChannelEndpointId& other) const {
46 return !operator==(other); 52 return !operator==(other);
47 } 53 }
48 // So that we can be used in |std::map|, etc. 54 // So that we can be used in |std::map|, etc.
49 bool operator<(const ChannelEndpointId& other) const { 55 bool operator<(const ChannelEndpointId& other) const {
50 return value_ < other.value_; 56 return value_ < other.value_;
51 } 57 }
52 58
53 bool is_valid() const { return !!value_; } 59 bool is_valid() const { return !!value_; }
60 bool is_remotely_allocated() const {
61 return !!(value_ & kRemotelyAllocatedFlag);
62 }
54 uint32_t value() const { return value_; } 63 uint32_t value() const { return value_; }
55 64
56 private: 65 private:
57 friend class LocalChannelEndpointIdGenerator; 66 friend class LocalChannelEndpointIdGenerator;
58 FRIEND_TEST_ALL_PREFIXES(LocalChannelEndpointIdGeneratorTest, WrapAround); 67 FRIEND_TEST_ALL_PREFIXES(LocalChannelEndpointIdGeneratorTest, WrapAround);
59 68
60 uint32_t value_; 69 uint32_t value_;
61 70
71 static const uint32_t kRemotelyAllocatedFlag = 0x80000000u;
72 static const uint32_t kLocallyAllocatedMask = ~kRemotelyAllocatedFlag;
73
62 // Copying and assignment allowed. 74 // Copying and assignment allowed.
63 }; 75 };
64 // This wrapper should add no overhead. 76 // This wrapper should add no overhead.
65 // TODO(vtl): Rewrite |sizeof(uint32_t)| as |sizeof(ChannelEndpointId::value)| 77 // TODO(vtl): Rewrite |sizeof(uint32_t)| as |sizeof(ChannelEndpointId::value)|
66 // once we have sufficient C++11 support. 78 // once we have sufficient C++11 support.
67 static_assert(sizeof(ChannelEndpointId) == sizeof(uint32_t), 79 static_assert(sizeof(ChannelEndpointId) == sizeof(uint32_t),
68 "ChannelEndpointId has incorrect size"); 80 "ChannelEndpointId has incorrect size");
69 81
70 // So logging macros and |DCHECK_EQ()|, etc. work. 82 // So logging macros and |DCHECK_EQ()|, etc. work.
71 inline std::ostream& operator<<(std::ostream& out, 83 inline std::ostream& operator<<(std::ostream& out,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #elif defined(COMPILER_MSVC) 126 #elif defined(COMPILER_MSVC)
115 127
116 inline size_t hash_value(mojo::system::ChannelEndpointId channel_endpoint_id) { 128 inline size_t hash_value(mojo::system::ChannelEndpointId channel_endpoint_id) {
117 return static_cast<size_t>(channel_endpoint_id.value()); 129 return static_cast<size_t>(channel_endpoint_id.value());
118 } 130 }
119 #endif 131 #endif
120 132
121 } // namespace BASE_HASH_NAMESPACE 133 } // namespace BASE_HASH_NAMESPACE
122 134
123 #endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 135 #endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/channel_endpoint_id.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698