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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
6 #define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
7
8 #include <map>
9
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/platform_thread.h"
14
15 template <typename T> struct DefaultSingletonTraits;
16
17 namespace base {
18
19 class BASE_EXPORT ThreadIdNameManager {
20 public:
21 static ThreadIdNameManager* GetInstance();
22
23 // Retrieve the name for the given id.
24 const char* GetNameForId(PlatformThreadId id);
25
26 // Set the name for the given id.
27 void SetNameForId(PlatformThreadId id, const char* name);
28
29 // Remove the name for the given id.
30 void RemoveNameForId(PlatformThreadId id);
31
32 // Retrieve the name version for this id. Used to quickly determine
33 // if a thread name has changed.
34 uint32 GetVersionForId(PlatformThreadId id);
35
36 private:
37 friend struct DefaultSingletonTraits<ThreadIdNameManager>;
38
39 ThreadIdNameManager();
40 ~ThreadIdNameManager();
41
42 // protectes id_to_name_
43 base::Lock lock_;
44
45 std::map<PlatformThreadId, char*> id_to_name_;
46 std::map<PlatformThreadId, uint32> id_to_version_;
47
48 uint32 current_version_;
49
50 DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
51 };
52
53 } // namespace base
54
55 #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698