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

Unified Diff: base/threading/thread_id_name_manager.h

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: Store a version number for the current name for fast comparisons. 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.h
diff --git a/base/threading/thread_id_name_manager.h b/base/threading/thread_id_name_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..9af81f6bce524679fabab37e8c1b38e0465cd812
--- /dev/null
+++ b/base/threading/thread_id_name_manager.h
@@ -0,0 +1,55 @@
+// 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.
+
+#ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
+#define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
+
+#include <map>
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/platform_thread.h"
+
+template <typename T> struct DefaultSingletonTraits;
+
+namespace base {
+
+class BASE_EXPORT ThreadIdNameManager {
+ public:
+ static ThreadIdNameManager* GetInstance();
+
+ // Retrieve the name for the given id.
+ const char* GetNameForId(PlatformThreadId id);
+
+ // Set the name for the given id.
+ void SetNameForId(PlatformThreadId id, const char* name);
+
+ // Remove the name for the given id.
+ void RemoveNameForId(PlatformThreadId id);
+
+ // Retrieve the name version for this id. Used to quickly determine
+ // if a thread name has changed.
+ uint32 GetVersionForId(PlatformThreadId id);
+
+ private:
+ friend struct DefaultSingletonTraits<ThreadIdNameManager>;
+
+ ThreadIdNameManager();
+ ~ThreadIdNameManager();
+
+ // protectes id_to_name_
+ base::Lock lock_;
+
+ std::map<PlatformThreadId, char*> id_to_name_;
+ std::map<PlatformThreadId, uint32> id_to_version_;
+
+ uint32 current_version_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
+};
+
+} // namespace base
+
+#endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698