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

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

Issue 7495031: trace_event support for thread names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove process names. With thread names, they are redundant. Created 9 years, 5 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
9 #include "base/threading/thread_local.h" 9 #include "base/threading/thread_local.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/debug/trace_event.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 namespace { 15 namespace {
15 16
16 // We use this thread-local variable to record whether or not a thread exited 17 // We use this thread-local variable to record whether or not a thread exited
17 // because its Stop method was called. This allows us to catch cases where 18 // because its Stop method was called. This allows us to catch cases where
18 // MessageLoop::Quit() is called directly, which is unexpected when using a 19 // MessageLoop::Quit() is called directly, which is unexpected when using a
19 // Thread to setup and run a MessageLoop. 20 // Thread to setup and run a MessageLoop.
20 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool( 21 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 void Thread::ThreadMain() { 144 void Thread::ThreadMain() {
144 { 145 {
145 // The message loop for this thread. 146 // The message loop for this thread.
146 MessageLoop message_loop(startup_data_->options.message_loop_type); 147 MessageLoop message_loop(startup_data_->options.message_loop_type);
147 148
148 // Complete the initialization of our Thread object. 149 // Complete the initialization of our Thread object.
149 thread_id_ = PlatformThread::CurrentId(); 150 thread_id_ = PlatformThread::CurrentId();
150 PlatformThread::SetName(name_.c_str()); 151 PlatformThread::SetName(name_.c_str());
151 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. 152 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
153 // Tell the name to TRACE_EVENT
154 debug::TraceLog::GetInstance()->SetCurrentThreadName(name_.c_str());
scheib 2011/07/26 18:47:16 Isn't this redundant with the call to PlatformThre
152 message_loop.set_thread_name(name_); 155 message_loop.set_thread_name(name_);
153 message_loop_ = &message_loop; 156 message_loop_ = &message_loop;
154 message_loop_proxy_ = MessageLoopProxy::CreateForCurrentThread(); 157 message_loop_proxy_ = MessageLoopProxy::CreateForCurrentThread();
155 158
156 // Let the thread do extra initialization. 159 // Let the thread do extra initialization.
157 // Let's do this before signaling we are started. 160 // Let's do this before signaling we are started.
158 Init(); 161 Init();
159 162
160 startup_data_->event.Signal(); 163 startup_data_->event.Signal();
161 // startup_data_ can't be touched anymore since the starting thread is now 164 // startup_data_ can't be touched anymore since the starting thread is now
162 // unlocked. 165 // unlocked.
163 166
164 Run(message_loop_); 167 Run(message_loop_);
165 168
166 // Let the thread do extra cleanup. 169 // Let the thread do extra cleanup.
167 CleanUp(); 170 CleanUp();
168 171
169 // Assert that MessageLoop::Quit was called by ThreadQuitTask. 172 // Assert that MessageLoop::Quit was called by ThreadQuitTask.
170 DCHECK(GetThreadWasQuitProperly()); 173 DCHECK(GetThreadWasQuitProperly());
171 174
172 // We can't receive messages anymore. 175 // We can't receive messages anymore.
173 message_loop_ = NULL; 176 message_loop_ = NULL;
174 message_loop_proxy_ = NULL; 177 message_loop_proxy_ = NULL;
175 } 178 }
176 thread_id_ = kInvalidThreadId; 179 thread_id_ = kInvalidThreadId;
177 } 180 }
178 181
179 } // namespace base 182 } // namespace base
OLDNEW
« base/threading/platform_thread_posix.cc ('K') | « base/threading/platform_thread_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698