Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ipc/ipc_message.h" | 5 #include "ipc/ipc_message.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 | 10 |
| 10 #if defined(OS_POSIX) | 11 #if defined(OS_POSIX) |
| 11 #include "ipc/file_descriptor_set_posix.h" | 12 #include "ipc/file_descriptor_set_posix.h" |
| 12 #endif | 13 #endif |
| 13 | 14 |
| 15 namespace { | |
| 16 | |
| 17 base::subtle::Atomic32 g_ref_num = 0; | |
| 18 | |
| 19 inline uint32 GetRefNumUpper24() { | |
|
jam
2012/08/31 23:07:55
nit: add a comment
jbates
2012/08/31 23:27:49
Done.
| |
| 20 int32 pid = base::debug::TraceLog::GetInstance()->process_id(); | |
| 21 int32 count = base::subtle::NoBarrier_AtomicIncrement(&g_ref_num, 1); | |
| 22 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the | |
| 23 // Process ID. With the current trace event buffer cap, the 14-bit count did | |
| 24 // not appear to wrap during a trace. Note that it is not a big deal if | |
| 25 // collisions occur, as this is only used for debugging and trace analysis. | |
| 26 return ((pid << 14) | (count & 0x3fff)) << 8; | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 14 namespace IPC { | 31 namespace IPC { |
| 15 | 32 |
| 16 //------------------------------------------------------------------------------ | 33 //------------------------------------------------------------------------------ |
| 17 | 34 |
| 18 Message::~Message() { | 35 Message::~Message() { |
| 19 } | 36 } |
| 20 | 37 |
| 21 Message::Message() | 38 Message::Message() |
| 22 : Pickle(sizeof(Header)) { | 39 : Pickle(sizeof(Header)) { |
| 23 header()->routing = header()->type = header()->flags = 0; | 40 header()->routing = header()->type = 0; |
| 41 header()->flags = GetRefNumUpper24(); | |
|
jam
2012/08/31 23:07:55
Are you sure this works with the reference builds?
jbates
2012/08/31 23:27:49
The code that accesses flags in this file just che
jam
2012/09/02 00:35:18
you can try running tests which use the reference
| |
| 24 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
| 25 header()->num_fds = 0; | 43 header()->num_fds = 0; |
| 26 header()->pad = 0; | 44 header()->pad = 0; |
| 27 #endif | 45 #endif |
| 28 InitLoggingVariables(); | 46 InitLoggingVariables(); |
| 29 } | 47 } |
| 30 | 48 |
| 31 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) | 49 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) |
| 32 : Pickle(sizeof(Header)) { | 50 : Pickle(sizeof(Header)) { |
| 33 header()->routing = routing_id; | 51 header()->routing = routing_id; |
| 34 header()->type = type; | 52 header()->type = type; |
| 35 header()->flags = priority; | 53 DCHECK((priority & 0xffffff00) == 0); |
| 54 header()->flags = priority | GetRefNumUpper24(); | |
| 36 #if defined(OS_POSIX) | 55 #if defined(OS_POSIX) |
| 37 header()->num_fds = 0; | 56 header()->num_fds = 0; |
| 38 header()->pad = 0; | 57 header()->pad = 0; |
| 39 #endif | 58 #endif |
| 40 InitLoggingVariables(); | 59 InitLoggingVariables(); |
| 41 } | 60 } |
| 42 | 61 |
| 43 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { | 62 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { |
| 44 InitLoggingVariables(); | 63 InitLoggingVariables(); |
| 45 } | 64 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 149 } |
| 131 | 150 |
| 132 void Message::EnsureFileDescriptorSet() { | 151 void Message::EnsureFileDescriptorSet() { |
| 133 if (file_descriptor_set_.get() == NULL) | 152 if (file_descriptor_set_.get() == NULL) |
| 134 file_descriptor_set_ = new FileDescriptorSet; | 153 file_descriptor_set_ = new FileDescriptorSet; |
| 135 } | 154 } |
| 136 | 155 |
| 137 #endif | 156 #endif |
| 138 | 157 |
| 139 } // namespace IPC | 158 } // namespace IPC |
| OLD | NEW |