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

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

Issue 23606030: Copy the thread name to the stack for debugging purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/thread_id_name_manager.h" 10 #include "base/threading/thread_id_name_manager.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 bool Thread::GetThreadWasQuitProperly() { 165 bool Thread::GetThreadWasQuitProperly() {
166 bool quit_properly = true; 166 bool quit_properly = true;
167 #ifndef NDEBUG 167 #ifndef NDEBUG
168 quit_properly = lazy_tls_bool.Pointer()->Get(); 168 quit_properly = lazy_tls_bool.Pointer()->Get();
169 #endif 169 #endif
170 return quit_properly; 170 return quit_properly;
171 } 171 }
172 172
173 void Thread::ThreadMain() { 173 void Thread::ThreadMain() {
174 { 174 {
175 #if defined(OS_MACOSX)
176 // Store the thread name on the stack to debug <http://crbug.com/274705>.
177 // End with a byte sequence of <EOT><BEL><NUL> to make it easier to grep in
178 // the minidump stack dump.
Mark Mentovai 2013/09/12 18:38:37 If you’re trying to make it easier to find in a mi
Robert Sesek 2013/09/12 18:47:53 If strlen(s2) < n, then it fills the remainder wit
179 const size_t kThreadNameSize = 50;
180 char thread_name[kThreadNameSize];
181 strncpy(thread_name, name_.c_str(), kThreadNameSize);
182 thread_name[kThreadNameSize - 1] = '\0';
183 thread_name[kThreadNameSize - 2] = '\7';
184 thread_name[kThreadNameSize - 3] = '\3';
Mark Mentovai 2013/09/12 18:38:37 How are you assuring that storage for variable, un
Robert Sesek 2013/09/12 18:47:53 Good point. Using base::debug::Alias() now at the
185 #endif
186
175 // The message loop for this thread. 187 // The message loop for this thread.
176 // Allocated on the heap to centralize any leak reports at this line. 188 // Allocated on the heap to centralize any leak reports at this line.
177 scoped_ptr<MessageLoop> message_loop( 189 scoped_ptr<MessageLoop> message_loop(
178 new MessageLoop(startup_data_->options.message_loop_type)); 190 new MessageLoop(startup_data_->options.message_loop_type));
179 191
180 // Complete the initialization of our Thread object. 192 // Complete the initialization of our Thread object.
181 thread_id_ = PlatformThread::CurrentId(); 193 thread_id_ = PlatformThread::CurrentId();
182 PlatformThread::SetName(name_.c_str()); 194 PlatformThread::SetName(name_.c_str());
183 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. 195 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
184 message_loop->set_thread_name(name_); 196 message_loop->set_thread_name(name_);
(...skipping 29 matching lines...) Expand all
214 226
215 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. 227 // Assert that MessageLoop::Quit was called by ThreadQuitHelper.
216 DCHECK(GetThreadWasQuitProperly()); 228 DCHECK(GetThreadWasQuitProperly());
217 229
218 // We can't receive messages anymore. 230 // We can't receive messages anymore.
219 message_loop_ = NULL; 231 message_loop_ = NULL;
220 } 232 }
221 } 233 }
222 234
223 } // namespace base 235 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698