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

Side by Side 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: Change to const char* from std::string 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 #include "base/threading/thread_id_name_manager.h"
6
7 #include "base/memory/singleton.h"
8
9 namespace base {
10
11 ThreadIdNameManager::ThreadIdNameManager() {
12 }
13
14 ThreadIdNameManager::~ThreadIdNameManager() {
15 }
16
17 ThreadIdNameManager* ThreadIdNameManager::GetInstance() {
18 return Singleton<ThreadIdNameManager,
19 LeakySingletonTraits<ThreadIdNameManager> >::get();
20 }
21
22 const char* ThreadIdNameManager::GetNameForId(PlatformThreadId id) {
23 base::AutoLock locked(lock_);
24
25 std::map<PlatformThreadId, const char*>::const_iterator it;
26 it = id_to_name_.find(id);
27 if (it == id_to_name_.end())
28 return NULL;
29 return it->second;
30 }
31
32 void ThreadIdNameManager::SetNameForId(PlatformThreadId id, const char* name) {
33 base::AutoLock locked(lock_);
34 id_to_name_[id] = name;
jar (doing other things) 2012/12/06 20:54:37 nit: can/should we have a DCHECK here to verify th
dsinclair 2012/12/10 16:24:36 It seems that being able to SetName multiple times
35 }
36
37 void ThreadIdNameManager::RemoveNameForId(PlatformThreadId id) {
38 base::AutoLock locked(lock_);
39 id_to_name_.erase(id);
jar (doing other things) 2012/12/06 20:54:37 nit: can/should we have a DCHECK here to verify th
dsinclair 2012/12/10 16:24:36 It's possible the name wouldn't be set, but in tha
40 }
41
42 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698