OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 { | 145 { |
146 // The message loop for this thread. | 146 // The message loop for this thread. |
147 MessageLoop message_loop(startup_data_->options.message_loop_type); | 147 MessageLoop message_loop(startup_data_->options.message_loop_type); |
148 | 148 |
149 // Complete the initialization of our Thread object. | 149 // Complete the initialization of our Thread object. |
150 thread_id_ = PlatformThread::CurrentId(); | 150 thread_id_ = PlatformThread::CurrentId(); |
151 PlatformThread::SetName(name_.c_str()); | 151 PlatformThread::SetName(name_.c_str()); |
152 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 message_loop.set_thread_name(name_); | 153 message_loop.set_thread_name(name_); |
154 message_loop_ = &message_loop; | 154 message_loop_ = &message_loop; |
| 155 #if defined(TRACK_ALL_TASK_OBJECTS) |
155 tracked_objects::ThreadData::InitializeThreadContext(name_); | 156 tracked_objects::ThreadData::InitializeThreadContext(name_); |
| 157 #endif // TRACK_ALL_TASK_OBJECTS |
156 | 158 |
157 // Let the thread do extra initialization. | 159 // Let the thread do extra initialization. |
158 // Let's do this before signaling we are started. | 160 // Let's do this before signaling we are started. |
159 Init(); | 161 Init(); |
160 | 162 |
161 startup_data_->event.Signal(); | 163 startup_data_->event.Signal(); |
162 // 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 |
163 // unlocked. | 165 // unlocked. |
164 | 166 |
165 Run(message_loop_); | 167 Run(message_loop_); |
166 | 168 |
167 // Let the thread do extra cleanup. | 169 // Let the thread do extra cleanup. |
168 CleanUp(); | 170 CleanUp(); |
169 | 171 |
170 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 172 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
171 DCHECK(GetThreadWasQuitProperly()); | 173 DCHECK(GetThreadWasQuitProperly()); |
172 | 174 |
173 // We can't receive messages anymore. | 175 // We can't receive messages anymore. |
174 message_loop_ = NULL; | 176 message_loop_ = NULL; |
175 } | 177 } |
176 thread_id_ = kInvalidThreadId; | 178 thread_id_ = kInvalidThreadId; |
177 } | 179 } |
178 | 180 |
179 } // namespace base | 181 } // namespace base |
OLD | NEW |