| OLD | NEW |
| 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/debug/alias.h" |
| 8 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "base/threading/thread_id_name_manager.h" | 11 #include "base/threading/thread_id_name_manager.h" |
| 11 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 14 | 15 |
| 15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 16 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
| 17 #endif | 18 #endif |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 bool Thread::GetThreadWasQuitProperly() { | 166 bool Thread::GetThreadWasQuitProperly() { |
| 166 bool quit_properly = true; | 167 bool quit_properly = true; |
| 167 #ifndef NDEBUG | 168 #ifndef NDEBUG |
| 168 quit_properly = lazy_tls_bool.Pointer()->Get(); | 169 quit_properly = lazy_tls_bool.Pointer()->Get(); |
| 169 #endif | 170 #endif |
| 170 return quit_properly; | 171 return quit_properly; |
| 171 } | 172 } |
| 172 | 173 |
| 173 void Thread::ThreadMain() { | 174 void Thread::ThreadMain() { |
| 174 { | 175 { |
| 176 #if defined(OS_MACOSX) |
| 177 // Store the thread name on the stack to debug <http://crbug.com/274705>. |
| 178 // End with a byte sequence of <EOT><BEL><NUL> to make it easier to grep in |
| 179 // the minidump stack dump. |
| 180 const size_t kThreadNameSize = 50; |
| 181 char thread_name[kThreadNameSize]; |
| 182 strncpy(thread_name, name_.c_str(), kThreadNameSize); |
| 183 thread_name[kThreadNameSize - 1] = '\0'; |
| 184 thread_name[kThreadNameSize - 2] = '\7'; |
| 185 thread_name[kThreadNameSize - 3] = '\3'; |
| 186 base::debug::Alias(thread_name); |
| 187 #endif |
| 188 |
| 175 // The message loop for this thread. | 189 // The message loop for this thread. |
| 176 // Allocated on the heap to centralize any leak reports at this line. | 190 // Allocated on the heap to centralize any leak reports at this line. |
| 177 scoped_ptr<MessageLoop> message_loop( | 191 scoped_ptr<MessageLoop> message_loop( |
| 178 new MessageLoop(startup_data_->options.message_loop_type)); | 192 new MessageLoop(startup_data_->options.message_loop_type)); |
| 179 | 193 |
| 180 // Complete the initialization of our Thread object. | 194 // Complete the initialization of our Thread object. |
| 181 thread_id_ = PlatformThread::CurrentId(); | 195 thread_id_ = PlatformThread::CurrentId(); |
| 182 PlatformThread::SetName(name_.c_str()); | 196 PlatformThread::SetName(name_.c_str()); |
| 183 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. | 197 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. |
| 184 message_loop->set_thread_name(name_); | 198 message_loop->set_thread_name(name_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 210 | 224 |
| 211 #if defined(OS_WIN) | 225 #if defined(OS_WIN) |
| 212 com_initializer.reset(); | 226 com_initializer.reset(); |
| 213 #endif | 227 #endif |
| 214 | 228 |
| 215 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 229 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
| 216 DCHECK(GetThreadWasQuitProperly()); | 230 DCHECK(GetThreadWasQuitProperly()); |
| 217 | 231 |
| 218 // We can't receive messages anymore. | 232 // We can't receive messages anymore. |
| 219 message_loop_ = NULL; | 233 message_loop_ = NULL; |
| 234 |
| 235 #if defined(OS_MACOSX) |
| 236 base::debug::Alias(thread_name); |
| 237 #endif |
| 220 } | 238 } |
| 221 } | 239 } |
| 222 | 240 |
| 223 } // namespace base | 241 } // namespace base |
| OLD | NEW |