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

Side by Side Diff: base/threading/thread_id_name_manager.h

Issue 14634009: Move Thread Name Mapping into ThreadFunc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ 5 #ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
6 #define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ 6 #define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 15
16 template <typename T> struct DefaultSingletonTraits; 16 template <typename T> struct DefaultSingletonTraits;
17 17
18 namespace base { 18 namespace base {
19 19
20 class BASE_EXPORT ThreadIdNameManager { 20 class BASE_EXPORT ThreadIdNameManager {
21 public: 21 public:
22 static ThreadIdNameManager* GetInstance(); 22 static ThreadIdNameManager* GetInstance();
23 23
24 static const char* GetDefaultInternedString(); 24 static const char* GetDefaultInternedString();
25 25
26 // Register the mapping between a thread |id| and |handle|.
27 void RegisterThread(PlatformThreadHandle* handle, PlatformThreadId id);
28
26 // Set the name for the given id. 29 // Set the name for the given id.
27 void SetName(PlatformThreadId id, const char* name); 30 void SetName(PlatformThreadId id, const char* name);
28 31
29 // Get the name for the given id. 32 // Get the name for the given id.
30 const char* GetName(PlatformThreadId id); 33 const char* GetName(PlatformThreadId id);
31 34
32 // Remove the name for the given id. 35 // Remove the name for the given id.
33 void RemoveName(PlatformThreadId id); 36 void RemoveName(PlatformThreadHandle* handle, PlatformThreadId id);
34 37
35 private: 38 private:
36 friend struct DefaultSingletonTraits<ThreadIdNameManager>; 39 friend struct DefaultSingletonTraits<ThreadIdNameManager>;
37 40
38 ThreadIdNameManager(); 41 ThreadIdNameManager();
39 ~ThreadIdNameManager(); 42 ~ThreadIdNameManager();
40 43
41 // lock_ protects both the thread_id_to_name_ and name_to_interned_name_ maps. 44 // lock_ protects both the thread_id_to_name_ and name_to_interned_name_ maps.
jar (doing other things) 2013/05/22 19:37:56 You probably want to update this comment, and your
dsinclair 2013/05/22 20:22:31 Done.
42 Lock lock_; 45 Lock lock_;
43 46
44 std::map<PlatformThreadId, std::string*> thread_id_to_interned_name_;
45 std::map<std::string, std::string*> name_to_interned_name_; 47 std::map<std::string, std::string*> name_to_interned_name_;
48 std::map<PlatformThreadId, PlatformThreadHandle*> thread_id_to_handle_;
49 std::map<PlatformThreadHandle*, std::string*> thread_handle_to_interned_name_;
50
51 // Treat the main process specially as it doesn't have a PlatformThreadHandle
52 std::string* main_process_name_;
53 PlatformThreadId main_process_id_;
46 54
47 DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager); 55 DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
48 }; 56 };
49 57
50 } // namespace base 58 } // namespace base
51 59
52 #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ 60 #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698