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

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: ThreadLocal for the current interned string value. Created 7 years, 11 months 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 #include <string>
10
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h"
15
16 template <typename T> struct DefaultSingletonTraits;
17
18 namespace base {
19
20 typedef int InternedString;
21 BASE_EXPORT extern const base::InternedString kDefaultInternedString;
22
23 class BASE_EXPORT ThreadIdNameManager {
24 public:
25
jar (doing other things) 2013/01/17 23:18:39 nit: remove blank line
dsinclair 2013/01/21 19:14:18 Done.
26 static ThreadIdNameManager* GetInstance();
27
28 // Set the name for the given id.
29 void SetNameForId(PlatformThreadId id, const char* name);
30
31 // Get the name for the given id.
32 const char* GetNameForId(PlatformThreadId id);
jar (doing other things) 2013/01/17 23:18:39 Why do we have a getter that gets the char* for t
dsinclair 2013/01/21 19:14:18 Done. Lost sight of the forest because of the tre
33
34 // Remove the name for the given id.
35 void RemoveNameForId(PlatformThreadId id);
36
37 // Retrieve the interned name for this thread.
38 InternedString GetInternedName(PlatformThreadId id);
39
40 // Retrieve the string value for the interned thread name.
41 const char* GetInternedStringValue(InternedString str);
42
43 private:
44 friend struct DefaultSingletonTraits<ThreadIdNameManager>;
45
46 ThreadIdNameManager();
47 ~ThreadIdNameManager();
48
49 // protectes id_to_name_
50 base::Lock lock_;
51
52 std::map<PlatformThreadId, base::InternedString> id_to_interned_name_;
jar (doing other things) 2013/01/17 23:18:39 nit: remove "base::" do this througout this heade
dsinclair 2013/01/21 19:14:18 Done.
53 std::map<base::InternedString, std::string> interned_name_to_name_;
54 std::map<std::string, base::InternedString> name_to_interned_name_;
jar (doing other things) 2013/01/17 23:18:39 nit: remove "base::"
dsinclair 2013/01/21 19:14:18 Done.
55
56 base::InternedString current_interned_name_;
jar (doing other things) 2013/01/17 23:18:39 Why not use something like interned_name_to_name_.
dsinclair 2013/01/21 19:14:18 Done.
57
58 DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
59 };
60
61 } // namespace base
62
63 #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698