| 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 "base/threading/thread_id_name_manager.h" | 5 #include "base/threading/thread_id_name_manager.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ThreadIdNameManager::RegisterThread(PlatformThreadHandle::Handle handle, | 43 void ThreadIdNameManager::RegisterThread(PlatformThreadHandle::Handle handle, |
| 44 PlatformThreadId id) { | 44 PlatformThreadId id) { |
| 45 AutoLock locked(lock_); | 45 AutoLock locked(lock_); |
| 46 thread_id_to_handle_[id] = handle; | 46 thread_id_to_handle_[id] = handle; |
| 47 thread_handle_to_interned_name_[handle] = | 47 thread_handle_to_interned_name_[handle] = |
| 48 name_to_interned_name_[kDefaultName]; | 48 name_to_interned_name_[kDefaultName]; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ThreadIdNameManager::SetName(PlatformThreadId id, const char* name) { | 51 void ThreadIdNameManager::SetName(PlatformThreadId id, |
| 52 std::string str_name(name); | 52 const std::string& name) { |
| 53 | |
| 54 AutoLock locked(lock_); | 53 AutoLock locked(lock_); |
| 55 NameToInternedNameMap::iterator iter = name_to_interned_name_.find(str_name); | 54 NameToInternedNameMap::iterator iter = name_to_interned_name_.find(name); |
| 56 std::string* leaked_str = NULL; | 55 std::string* leaked_str = NULL; |
| 57 if (iter != name_to_interned_name_.end()) { | 56 if (iter != name_to_interned_name_.end()) { |
| 58 leaked_str = iter->second; | 57 leaked_str = iter->second; |
| 59 } else { | 58 } else { |
| 60 leaked_str = new std::string(str_name); | 59 leaked_str = new std::string(name); |
| 61 name_to_interned_name_[str_name] = leaked_str; | 60 name_to_interned_name_[name] = leaked_str; |
| 62 } | 61 } |
| 63 | 62 |
| 64 ThreadIdToHandleMap::iterator id_to_handle_iter = | 63 ThreadIdToHandleMap::iterator id_to_handle_iter = |
| 65 thread_id_to_handle_.find(id); | 64 thread_id_to_handle_.find(id); |
| 66 | 65 |
| 67 // The main thread of a process will not be created as a Thread object which | 66 // The main thread of a process will not be created as a Thread object which |
| 68 // means there is no PlatformThreadHandler registered. | 67 // means there is no PlatformThreadHandler registered. |
| 69 if (id_to_handle_iter == thread_id_to_handle_.end()) { | 68 if (id_to_handle_iter == thread_id_to_handle_.end()) { |
| 70 main_process_name_ = leaked_str; | 69 main_process_name_ = leaked_str; |
| 71 main_process_id_ = id; | 70 main_process_id_ = id; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 DCHECK((id_to_handle_iter!= thread_id_to_handle_.end())); | 103 DCHECK((id_to_handle_iter!= thread_id_to_handle_.end())); |
| 105 // The given |id| may have been re-used by the system. Make sure the | 104 // The given |id| may have been re-used by the system. Make sure the |
| 106 // mapping points to the provided |handle| before removal. | 105 // mapping points to the provided |handle| before removal. |
| 107 if (id_to_handle_iter->second != handle) | 106 if (id_to_handle_iter->second != handle) |
| 108 return; | 107 return; |
| 109 | 108 |
| 110 thread_id_to_handle_.erase(id_to_handle_iter); | 109 thread_id_to_handle_.erase(id_to_handle_iter); |
| 111 } | 110 } |
| 112 | 111 |
| 113 } // namespace base | 112 } // namespace base |
| OLD | NEW |