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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 // We should only be called on the same thread that started us. | 125 // We should only be called on the same thread that started us. |
126 DCHECK_NE(thread_id_, PlatformThread::CurrentId()); | 126 DCHECK_NE(thread_id_, PlatformThread::CurrentId()); |
127 | 127 |
128 // We had better have a message loop at this point! If we do not, then it | 128 // We had better have a message loop at this point! If we do not, then it |
129 // most likely means that the thread terminated unexpectedly, probably due | 129 // most likely means that the thread terminated unexpectedly, probably due |
130 // to someone calling Quit() on our message loop directly. | 130 // to someone calling Quit() on our message loop directly. |
131 DCHECK(message_loop_); | 131 DCHECK(message_loop_); |
132 | 132 |
133 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); | 133 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); |
134 | |
135 // The thread can't receive messages anymore. | |
136 message_loop_ = NULL; | |
137 } | 134 } |
138 | 135 |
139 void Thread::ThreadMain() { | 136 void Thread::ThreadMain() { |
140 // The message loop for this thread. | 137 // The message loop for this thread. |
141 MessageLoop message_loop(startup_data_->options.message_loop_type); | 138 MessageLoop message_loop(startup_data_->options.message_loop_type); |
142 | 139 |
143 // Complete the initialization of our Thread object. | 140 // Complete the initialization of our Thread object. |
144 thread_id_ = PlatformThread::CurrentId(); | 141 thread_id_ = PlatformThread::CurrentId(); |
145 PlatformThread::SetName(name_.c_str()); | 142 PlatformThread::SetName(name_.c_str()); |
146 message_loop.set_thread_name(name_); | 143 message_loop.set_thread_name(name_); |
(...skipping 12 matching lines...) Expand all Loading... |
159 CleanUp(); | 156 CleanUp(); |
160 | 157 |
161 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 158 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
162 DCHECK(GetThreadWasQuitProperly()); | 159 DCHECK(GetThreadWasQuitProperly()); |
163 | 160 |
164 // We can't receive messages anymore. | 161 // We can't receive messages anymore. |
165 message_loop_ = NULL; | 162 message_loop_ = NULL; |
166 } | 163 } |
167 | 164 |
168 } // namespace base | 165 } // namespace base |
OLD | NEW |