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 // Create a reference number for identifying IPC messages in traces. The return |
| 20 // values has the reference number stored in the upper 24 bits, leaving the low |
| 21 // 8 bits set to 0 for use as flags. |
| 22 inline uint32 GetRefNumUpper24() { |
| 23 base::debug::TraceLog* trace_log = base::debug::TraceLog::GetInstance(); |
| 24 int32 pid = trace_log ? trace_log->process_id() : 0; |
| 25 int32 count = base::subtle::NoBarrier_AtomicIncrement(&g_ref_num, 1); |
| 26 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the |
| 27 // Process ID. With the current trace event buffer cap, the 14-bit count did |
| 28 // not appear to wrap during a trace. Note that it is not a big deal if |
| 29 // collisions occur, as this is only used for debugging and trace analysis. |
| 30 return ((pid << 14) | (count & 0x3fff)) << 8; |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
14 namespace IPC { | 35 namespace IPC { |
15 | 36 |
16 //------------------------------------------------------------------------------ | 37 //------------------------------------------------------------------------------ |
17 | 38 |
18 Message::~Message() { | 39 Message::~Message() { |
19 } | 40 } |
20 | 41 |
21 Message::Message() | 42 Message::Message() |
22 : Pickle(sizeof(Header)) { | 43 : Pickle(sizeof(Header)) { |
23 header()->routing = header()->type = header()->flags = 0; | 44 header()->routing = header()->type = 0; |
| 45 header()->flags = GetRefNumUpper24(); |
24 #if defined(OS_POSIX) | 46 #if defined(OS_POSIX) |
25 header()->num_fds = 0; | 47 header()->num_fds = 0; |
26 header()->pad = 0; | 48 header()->pad = 0; |
27 #endif | 49 #endif |
28 InitLoggingVariables(); | 50 InitLoggingVariables(); |
29 } | 51 } |
30 | 52 |
31 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) | 53 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) |
32 : Pickle(sizeof(Header)) { | 54 : Pickle(sizeof(Header)) { |
33 header()->routing = routing_id; | 55 header()->routing = routing_id; |
34 header()->type = type; | 56 header()->type = type; |
35 header()->flags = priority; | 57 DCHECK((priority & 0xffffff00) == 0); |
| 58 header()->flags = priority | GetRefNumUpper24(); |
36 #if defined(OS_POSIX) | 59 #if defined(OS_POSIX) |
37 header()->num_fds = 0; | 60 header()->num_fds = 0; |
38 header()->pad = 0; | 61 header()->pad = 0; |
39 #endif | 62 #endif |
40 InitLoggingVariables(); | 63 InitLoggingVariables(); |
41 } | 64 } |
42 | 65 |
43 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { | 66 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { |
44 InitLoggingVariables(); | 67 InitLoggingVariables(); |
45 } | 68 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 153 } |
131 | 154 |
132 void Message::EnsureFileDescriptorSet() { | 155 void Message::EnsureFileDescriptorSet() { |
133 if (file_descriptor_set_.get() == NULL) | 156 if (file_descriptor_set_.get() == NULL) |
134 file_descriptor_set_ = new FileDescriptorSet; | 157 file_descriptor_set_ = new FileDescriptorSet; |
135 } | 158 } |
136 | 159 |
137 #endif | 160 #endif |
138 | 161 |
139 } // namespace IPC | 162 } // namespace IPC |
OLD | NEW |