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/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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK_NE(thread_id_, PlatformThread::CurrentId()); | 128 DCHECK_NE(thread_id_, PlatformThread::CurrentId()); |
129 | 129 |
130 // We had better have a message loop at this point! If we do not, then it | 130 // We had better have a message loop at this point! If we do not, then it |
131 // most likely means that the thread terminated unexpectedly, probably due | 131 // most likely means that the thread terminated unexpectedly, probably due |
132 // to someone calling Quit() on our message loop directly. | 132 // to someone calling Quit() on our message loop directly. |
133 DCHECK(message_loop_); | 133 DCHECK(message_loop_); |
134 | 134 |
135 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); | 135 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); |
136 } | 136 } |
137 | 137 |
| 138 void Thread::Run(MessageLoop* message_loop) { |
| 139 message_loop->Run(); |
| 140 } |
| 141 |
138 void Thread::ThreadMain() { | 142 void Thread::ThreadMain() { |
139 // The message loop for this thread. | 143 // The message loop for this thread. |
140 MessageLoop message_loop(startup_data_->options.message_loop_type); | 144 MessageLoop message_loop(startup_data_->options.message_loop_type); |
141 | 145 |
142 // Complete the initialization of our Thread object. | 146 // Complete the initialization of our Thread object. |
143 thread_id_ = PlatformThread::CurrentId(); | 147 thread_id_ = PlatformThread::CurrentId(); |
144 PlatformThread::SetName(name_.c_str()); | 148 PlatformThread::SetName(name_.c_str()); |
145 message_loop.set_thread_name(name_); | 149 message_loop.set_thread_name(name_); |
146 message_loop_ = &message_loop; | 150 message_loop_ = &message_loop; |
147 | 151 |
148 // Let the thread do extra initialization. | 152 // Let the thread do extra initialization. |
149 // Let's do this before signaling we are started. | 153 // Let's do this before signaling we are started. |
150 Init(); | 154 Init(); |
151 | 155 |
152 startup_data_->event.Signal(); | 156 startup_data_->event.Signal(); |
153 // startup_data_ can't be touched anymore since the starting thread is now | 157 // startup_data_ can't be touched anymore since the starting thread is now |
154 // unlocked. | 158 // unlocked. |
155 | 159 |
156 message_loop.Run(); | 160 Run(message_loop_); |
157 | 161 |
158 // Let the thread do extra cleanup. | 162 // Let the thread do extra cleanup. |
159 CleanUp(); | 163 CleanUp(); |
160 | 164 |
161 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 165 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
162 DCHECK(GetThreadWasQuitProperly()); | 166 DCHECK(GetThreadWasQuitProperly()); |
163 | 167 |
164 // We can't receive messages anymore. | 168 // We can't receive messages anymore. |
165 message_loop_ = NULL; | 169 message_loop_ = NULL; |
166 thread_id_ = 0; | 170 thread_id_ = 0; |
167 } | 171 } |
168 | 172 |
169 } // namespace base | 173 } // namespace base |
OLD | NEW |