Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: base/threading/thread_id_name_manager.cc

Issue 11438022: Add ability to retrieve a thread_name given a thread_id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change to const char* from std::string Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698