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

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: Move the set to PlatformThread::SetName so we catch any name changes. 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..4374aa52bc153858656219e071aebb046d520d0e
--- /dev/null
+++ b/base/threading/thread_id_name_manager.cc
@@ -0,0 +1,46 @@
+// 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>::get();
+}
+
+bool ThreadIdNameManager::GetNameForId(PlatformThreadId id, std::string* name) {
+ if (name == NULL)
+ return false;
+
+ base::AutoLock locked(lock_);
+
+ std::map<PlatformThreadId, std::string>::const_iterator it;
+ it = id_to_name_.find(id);
+ if (it == id_to_name_.end())
+ return false;
+
+ *name = it->second;
+ return true;
+}
+
+void ThreadIdNameManager::SetNameForId(PlatformThreadId id, std::string name) {
+ base::AutoLock locked(lock_);
+ id_to_name_[id] = name;
+}
+
+void ThreadIdNameManager::RemoveNameForId(PlatformThreadId id) {
+ base::AutoLock locked(lock_);
+ id_to_name_.erase(id);
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698