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

Side by Side Diff: base/threading/simple_thread.cc

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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "base/threading/simple_thread.h" 5 #include "base/threading/simple_thread.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "base/threading/thread_id_name_manager.h"
10 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 SimpleThread::SimpleThread(const std::string& name_prefix) 15 SimpleThread::SimpleThread(const std::string& name_prefix)
15 : name_prefix_(name_prefix), name_(name_prefix), 16 : name_prefix_(name_prefix), name_(name_prefix),
16 thread_(), event_(true, false), tid_(0), joined_(false) { 17 thread_(), event_(true, false), tid_(0), joined_(false) {
17 } 18 }
18 19
19 SimpleThread::SimpleThread(const std::string& name_prefix, 20 SimpleThread::SimpleThread(const std::string& name_prefix,
(...skipping 12 matching lines...) Expand all
32 bool success = PlatformThread::Create(options_.stack_size(), this, &thread_); 33 bool success = PlatformThread::Create(options_.stack_size(), this, &thread_);
33 DCHECK(success); 34 DCHECK(success);
34 base::ThreadRestrictions::ScopedAllowWait allow_wait; 35 base::ThreadRestrictions::ScopedAllowWait allow_wait;
35 event_.Wait(); // Wait for the thread to complete initialization. 36 event_.Wait(); // Wait for the thread to complete initialization.
36 } 37 }
37 38
38 void SimpleThread::Join() { 39 void SimpleThread::Join() {
39 DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread."; 40 DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread.";
40 DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times."; 41 DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times.";
41 PlatformThread::Join(thread_); 42 PlatformThread::Join(thread_);
43 ThreadIdNameManager::GetInstance()->RemoveName(&thread_, tid_);
jar (doing other things) 2013/05/22 19:37:56 This still scares me a bit if I'm worried about ra
dsinclair 2013/05/22 20:22:31 The ThreadIdNameManager code takes care of this. W
42 joined_ = true; 44 joined_ = true;
43 } 45 }
44 46
45 bool SimpleThread::HasBeenStarted() { 47 bool SimpleThread::HasBeenStarted() {
46 base::ThreadRestrictions::ScopedAllowWait allow_wait; 48 base::ThreadRestrictions::ScopedAllowWait allow_wait;
47 return event_.IsSignaled(); 49 return event_.IsSignaled();
48 } 50 }
49 51
50 void SimpleThread::ThreadMain() { 52 void SimpleThread::ThreadMain() {
51 tid_ = PlatformThread::CurrentId(); 53 tid_ = PlatformThread::CurrentId();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 152
151 // A NULL delegate pointer signals us to quit. 153 // A NULL delegate pointer signals us to quit.
152 if (!work) 154 if (!work)
153 break; 155 break;
154 156
155 work->Run(); 157 work->Run();
156 } 158 }
157 } 159 }
158 160
159 } // namespace base 161 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698