OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/run_loop.h" |
10 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 12 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
12 #include "base/threading/thread_id_name_manager.h" | 13 #include "base/threading/thread_id_name_manager.h" |
13 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 | 17 |
17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
18 #include "base/win/scoped_com_initializer.h" | 19 #include "base/win/scoped_com_initializer.h" |
19 #endif | 20 #endif |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // starts / started the new thread so we need no locking here.) | 195 // starts / started the new thread so we need no locking here.) |
195 if (message_loop_ && !stopping_) | 196 if (message_loop_ && !stopping_) |
196 return true; | 197 return true; |
197 // Otherwise check the running_ flag, which is set to true by the new thread | 198 // Otherwise check the running_ flag, which is set to true by the new thread |
198 // only while it is inside Run(). | 199 // only while it is inside Run(). |
199 AutoLock lock(running_lock_); | 200 AutoLock lock(running_lock_); |
200 return running_; | 201 return running_; |
201 } | 202 } |
202 | 203 |
203 void Thread::Run(MessageLoop* message_loop) { | 204 void Thread::Run(MessageLoop* message_loop) { |
204 message_loop->Run(); | 205 RunLoop().Run(); |
205 } | 206 } |
206 | 207 |
207 void Thread::SetThreadWasQuitProperly(bool flag) { | 208 void Thread::SetThreadWasQuitProperly(bool flag) { |
208 lazy_tls_bool.Pointer()->Set(flag); | 209 lazy_tls_bool.Pointer()->Set(flag); |
209 } | 210 } |
210 | 211 |
211 bool Thread::GetThreadWasQuitProperly() { | 212 bool Thread::GetThreadWasQuitProperly() { |
212 bool quit_properly = true; | 213 bool quit_properly = true; |
213 #ifndef NDEBUG | 214 #ifndef NDEBUG |
214 quit_properly = lazy_tls_bool.Pointer()->Get(); | 215 quit_properly = lazy_tls_bool.Pointer()->Get(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // allow this. | 273 // allow this. |
273 DCHECK(GetThreadWasQuitProperly()); | 274 DCHECK(GetThreadWasQuitProperly()); |
274 } | 275 } |
275 | 276 |
276 // We can't receive messages anymore. | 277 // We can't receive messages anymore. |
277 // (The message loop is destructed at the end of this block) | 278 // (The message loop is destructed at the end of this block) |
278 message_loop_ = nullptr; | 279 message_loop_ = nullptr; |
279 } | 280 } |
280 | 281 |
281 } // namespace base | 282 } // namespace base |
OLD | NEW |