OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/threading/thread_id_name_manager.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 |
| 9 namespace base { |
| 10 |
| 11 ThreadIdNameManager::ThreadIdNameManager() { |
| 12 } |
| 13 |
| 14 ThreadIdNameManager::~ThreadIdNameManager() { |
| 15 } |
| 16 |
| 17 ThreadIdNameManager* ThreadIdNameManager::GetInstance() { |
| 18 return Singleton<ThreadIdNameManager>::get(); |
| 19 } |
| 20 |
| 21 bool ThreadIdNameManager::GetNameForId(PlatformThreadId id, std::string* name) { |
| 22 if (name == NULL) |
| 23 return false; |
| 24 |
| 25 base::AutoLock locked(lock_); |
| 26 |
| 27 std::map<PlatformThreadId, std::string>::const_iterator it; |
| 28 it = id_to_name_.find(id); |
| 29 if (it == id_to_name_.end()) |
| 30 return false; |
| 31 |
| 32 *name = it->second; |
| 33 return true; |
| 34 } |
| 35 |
| 36 void ThreadIdNameManager::SetNameForId(PlatformThreadId id, std::string name) { |
| 37 base::AutoLock locked(lock_); |
| 38 id_to_name_[id] = name; |
| 39 } |
| 40 |
| 41 void ThreadIdNameManager::RemoveNameForId(PlatformThreadId id) { |
| 42 base::AutoLock locked(lock_); |
| 43 id_to_name_.erase(id); |
| 44 } |
| 45 |
| 46 } // namespace base |
OLD | NEW |