Index: base/threading/thread_id_name_manager.cc |
diff --git a/base/threading/thread_id_name_manager.cc b/base/threading/thread_id_name_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6f429c2aa3c7518a643aec14aa66d17b86b3b60e |
--- /dev/null |
+++ b/base/threading/thread_id_name_manager.cc |
@@ -0,0 +1,42 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/threading/thread_id_name_manager.h" |
+ |
+#include "base/memory/singleton.h" |
+ |
+namespace base { |
+ |
+ThreadIdNameManager::ThreadIdNameManager() { |
+} |
+ |
+ThreadIdNameManager::~ThreadIdNameManager() { |
+} |
+ |
+ThreadIdNameManager* ThreadIdNameManager::GetInstance() { |
+ return Singleton<ThreadIdNameManager, |
+ LeakySingletonTraits<ThreadIdNameManager> >::get(); |
+} |
+ |
+const char* ThreadIdNameManager::GetNameForId(PlatformThreadId id) { |
+ base::AutoLock locked(lock_); |
+ |
+ std::map<PlatformThreadId, const char*>::const_iterator it; |
+ it = id_to_name_.find(id); |
+ if (it == id_to_name_.end()) |
+ return NULL; |
+ return it->second; |
+} |
+ |
+void ThreadIdNameManager::SetNameForId(PlatformThreadId id, const char* name) { |
+ base::AutoLock locked(lock_); |
+ id_to_name_[id] = name; |
jar (doing other things)
2012/12/06 20:54:37
nit: can/should we have a DCHECK here to verify th
dsinclair
2012/12/10 16:24:36
It seems that being able to SetName multiple times
|
+} |
+ |
+void ThreadIdNameManager::RemoveNameForId(PlatformThreadId id) { |
+ base::AutoLock locked(lock_); |
+ id_to_name_.erase(id); |
jar (doing other things)
2012/12/06 20:54:37
nit: can/should we have a DCHECK here to verify th
dsinclair
2012/12/10 16:24:36
It's possible the name wouldn't be set, but in tha
|
+} |
+ |
+} // namespace base |