| 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 18 matching lines...) Expand all Loading... |
| 29 DCHECK(thread_id_map->empty()); | 29 DCHECK(thread_id_map->empty()); |
| 30 | 30 |
| 31 // First, try truncating each 64-bit thread ID to 32 bits. If that’s possible | 31 // First, try truncating each 64-bit thread ID to 32 bits. If that’s possible |
| 32 // for each unique 64-bit thread ID, then this will be used as the mapping. | 32 // for each unique 64-bit thread ID, then this will be used as the mapping. |
| 33 // This preserves as much of the original thread ID as possible when feasible. | 33 // This preserves as much of the original thread ID as possible when feasible. |
| 34 bool collision = false; | 34 bool collision = false; |
| 35 std::set<uint32_t> thread_ids_32; | 35 std::set<uint32_t> thread_ids_32; |
| 36 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { | 36 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { |
| 37 uint64_t thread_id_64 = thread_snapshot->ThreadID(); | 37 uint64_t thread_id_64 = thread_snapshot->ThreadID(); |
| 38 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { | 38 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { |
| 39 uint32_t thread_id_32 = thread_id_64; | 39 uint32_t thread_id_32 = static_cast<uint32_t>(thread_id_64); |
| 40 if (thread_ids_32.find(thread_id_32) != thread_ids_32.end()) { | 40 if (thread_ids_32.find(thread_id_32) != thread_ids_32.end()) { |
| 41 collision = true; | 41 collision = true; |
| 42 break; | 42 break; |
| 43 } | 43 } |
| 44 thread_ids_32.insert(thread_id_32); | 44 thread_ids_32.insert(thread_id_32); |
| 45 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)); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 if (collision) { | 49 if (collision) { |
| 50 // 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 |
| 51 // 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 |
| 52 // bear any resemblance to the original 64-bit thread IDs. | 52 // bear any resemblance to the original 64-bit thread IDs. |
| 53 thread_id_map->clear(); | 53 thread_id_map->clear(); |
| 54 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { | 54 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { |
| 55 uint64_t thread_id_64 = thread_snapshot->ThreadID(); | 55 uint64_t thread_id_64 = thread_snapshot->ThreadID(); |
| 56 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()) { |
| 57 uint32_t thread_id_32 = thread_id_map->size(); | 57 uint32_t thread_id_32 = thread_id_map->size(); |
| 58 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); | 58 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 DCHECK_LE(thread_id_map->size(), std::numeric_limits<uint32_t>::max()); | 62 DCHECK_LE(thread_id_map->size(), std::numeric_limits<uint32_t>::max()); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace crashpad | 66 } // namespace crashpad |
| OLD | NEW |