OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // First, try truncating each 64-bit thread ID to 32 bits. If that’s possible | 32 // First, try truncating each 64-bit thread ID to 32 bits. If that’s possible |
33 // for each unique 64-bit thread ID, then this will be used as the mapping. | 33 // for each unique 64-bit thread ID, then this will be used as the mapping. |
34 // This preserves as much of the original thread ID as possible when feasible. | 34 // This preserves as much of the original thread ID as possible when feasible. |
35 bool collision = false; | 35 bool collision = false; |
36 std::set<uint32_t> thread_ids_32; | 36 std::set<uint32_t> thread_ids_32; |
37 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { | 37 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { |
38 uint64_t thread_id_64 = thread_snapshot->ThreadID(); | 38 uint64_t thread_id_64 = thread_snapshot->ThreadID(); |
39 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { | 39 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { |
40 uint32_t thread_id_32 = static_cast<uint32_t>(thread_id_64); | 40 uint32_t thread_id_32 = static_cast<uint32_t>(thread_id_64); |
41 if (thread_ids_32.find(thread_id_32) != thread_ids_32.end()) { | 41 if (!thread_ids_32.insert(thread_id_32).second) { |
42 collision = true; | 42 collision = true; |
43 break; | 43 break; |
44 } | 44 } |
45 thread_ids_32.insert(thread_id_32); | |
46 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); | 45 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); |
47 } | 46 } |
48 } | 47 } |
49 | 48 |
50 if (collision) { | 49 if (collision) { |
51 // Since there was a collision, go back and assign each unique 64-bit thread | 50 // Since there was a collision, go back and assign each unique 64-bit thread |
52 // ID its own sequential 32-bit equivalent. The 32-bit thread IDs will not | 51 // ID its own sequential 32-bit equivalent. The 32-bit thread IDs will not |
53 // bear any resemblance to the original 64-bit thread IDs. | 52 // bear any resemblance to the original 64-bit thread IDs. |
54 thread_id_map->clear(); | 53 thread_id_map->clear(); |
55 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { | 54 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { |
56 uint64_t thread_id_64 = thread_snapshot->ThreadID(); | 55 uint64_t thread_id_64 = thread_snapshot->ThreadID(); |
57 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { | 56 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { |
58 uint32_t thread_id_32 = | 57 uint32_t thread_id_32 = |
59 base::checked_cast<uint32_t>(thread_id_map->size()); | 58 base::checked_cast<uint32_t>(thread_id_map->size()); |
60 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); | 59 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 DCHECK_LE(thread_id_map->size(), std::numeric_limits<uint32_t>::max()); | 63 DCHECK_LE(thread_id_map->size(), std::numeric_limits<uint32_t>::max()); |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 } // namespace crashpad | 67 } // namespace crashpad |
OLD | NEW |