| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/thread.h" | 5 #include "base/thread.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/thread_local.h" | 9 #include "base/thread_local.h" |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void Thread::ThreadMain() { | 136 void Thread::ThreadMain() { |
| 137 // The message loop for this thread. | 137 // The message loop for this thread. |
| 138 MessageLoop message_loop(startup_data_->options.message_loop_type); | 138 MessageLoop message_loop(startup_data_->options.message_loop_type); |
| 139 | 139 |
| 140 // Complete the initialization of our Thread object. | 140 // Complete the initialization of our Thread object. |
| 141 thread_id_ = PlatformThread::CurrentId(); | 141 thread_id_ = PlatformThread::CurrentId(); |
| 142 PlatformThread::SetName(name_.c_str()); | 142 PlatformThread::SetName(name_.c_str()); |
| 143 message_loop.set_thread_name(name_); | 143 message_loop.set_thread_name(name_); |
| 144 message_loop_ = &message_loop; | 144 message_loop_ = &message_loop; |
| 145 | 145 |
| 146 // Let the thread do extra initialization. |
| 147 // Let's do this before signaling we are started. |
| 148 Init(); |
| 149 |
| 146 startup_data_->event.Signal(); | 150 startup_data_->event.Signal(); |
| 147 // startup_data_ can't be touched anymore since the starting thread is now | 151 // startup_data_ can't be touched anymore since the starting thread is now |
| 148 // unlocked. | 152 // unlocked. |
| 149 | 153 |
| 150 // Let the thread do extra initialization. | |
| 151 Init(); | |
| 152 | |
| 153 message_loop.Run(); | 154 message_loop.Run(); |
| 154 | 155 |
| 155 // Let the thread do extra cleanup. | 156 // Let the thread do extra cleanup. |
| 156 CleanUp(); | 157 CleanUp(); |
| 157 | 158 |
| 158 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 159 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
| 159 DCHECK(GetThreadWasQuitProperly()); | 160 DCHECK(GetThreadWasQuitProperly()); |
| 160 | 161 |
| 161 // We can't receive messages anymore. | 162 // We can't receive messages anymore. |
| 162 message_loop_ = NULL; | 163 message_loop_ = NULL; |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace base | 166 } // namespace base |
| OLD | NEW |