| OLD | NEW |
| 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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 bool quit_properly = true; | 136 bool quit_properly = true; |
| 137 #ifndef NDEBUG | 137 #ifndef NDEBUG |
| 138 quit_properly = lazy_tls_bool.Pointer()->Get(); | 138 quit_properly = lazy_tls_bool.Pointer()->Get(); |
| 139 #endif | 139 #endif |
| 140 return quit_properly; | 140 return quit_properly; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void Thread::ThreadMain() { | 143 void Thread::ThreadMain() { |
| 144 { | 144 { |
| 145 // The message loop for this thread. | 145 // The message loop for this thread. |
| 146 MessageLoop message_loop(startup_data_->options.message_loop_type); | 146 MessageLoop message_loop(name_.c_str(), |
| 147 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 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. | |
| 152 message_loop.set_thread_name(name_); | 151 message_loop.set_thread_name(name_); |
| 153 message_loop_ = &message_loop; | 152 message_loop_ = &message_loop; |
| 154 message_loop_proxy_ = MessageLoopProxy::CreateForCurrentThread(); | 153 message_loop_proxy_ = MessageLoopProxy::CreateForCurrentThread(); |
| 155 | 154 |
| 156 // Let the thread do extra initialization. | 155 // Let the thread do extra initialization. |
| 157 // Let's do this before signaling we are started. | 156 // Let's do this before signaling we are started. |
| 158 Init(); | 157 Init(); |
| 159 | 158 |
| 160 startup_data_->event.Signal(); | 159 startup_data_->event.Signal(); |
| 161 // startup_data_ can't be touched anymore since the starting thread is now | 160 // startup_data_ can't be touched anymore since the starting thread is now |
| 162 // unlocked. | 161 // unlocked. |
| 163 | 162 |
| 164 Run(message_loop_); | 163 Run(message_loop_); |
| 165 | 164 |
| 166 // Let the thread do extra cleanup. | 165 // Let the thread do extra cleanup. |
| 167 CleanUp(); | 166 CleanUp(); |
| 168 | 167 |
| 169 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 168 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
| 170 DCHECK(GetThreadWasQuitProperly()); | 169 DCHECK(GetThreadWasQuitProperly()); |
| 171 | 170 |
| 172 // We can't receive messages anymore. | 171 // We can't receive messages anymore. |
| 173 message_loop_ = NULL; | 172 message_loop_ = NULL; |
| 174 message_loop_proxy_ = NULL; | 173 message_loop_proxy_ = NULL; |
| 175 } | 174 } |
| 176 thread_id_ = kInvalidThreadId; | 175 thread_id_ = kInvalidThreadId; |
| 177 } | 176 } |
| 178 | 177 |
| 179 } // namespace base | 178 } // namespace base |
| OLD | NEW |