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" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // We use this thread-local variable to record whether or not a thread exited | 17 // We use this thread-local variable to record whether or not a thread exited |
18 // because its Stop method was called. This allows us to catch cases where | 18 // because its Stop method was called. This allows us to catch cases where |
19 // MessageLoop::Quit() is called directly, which is unexpected when using a | 19 // MessageLoop::Quit() is called directly, which is unexpected when using a |
20 // Thread to setup and run a MessageLoop. | 20 // Thread to setup and run a MessageLoop. |
21 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool( | 21 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool = |
22 base::LINKER_INITIALIZED); | 22 LAZY_INSTANCE_INITIALIZER; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 // This task is used to trigger the message loop to exit. | 26 // This task is used to trigger the message loop to exit. |
27 class ThreadQuitTask : public Task { | 27 class ThreadQuitTask : public Task { |
28 public: | 28 public: |
29 virtual void Run() { | 29 virtual void Run() { |
30 MessageLoop::current()->Quit(); | 30 MessageLoop::current()->Quit(); |
31 Thread::SetThreadWasQuitProperly(true); | 31 Thread::SetThreadWasQuitProperly(true); |
32 } | 32 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Assert that MessageLoop::Quit was called by ThreadQuitTask. | 170 // Assert that MessageLoop::Quit was called by ThreadQuitTask. |
171 DCHECK(GetThreadWasQuitProperly()); | 171 DCHECK(GetThreadWasQuitProperly()); |
172 | 172 |
173 // We can't receive messages anymore. | 173 // We can't receive messages anymore. |
174 message_loop_ = NULL; | 174 message_loop_ = NULL; |
175 } | 175 } |
176 thread_id_ = kInvalidThreadId; | 176 thread_id_ = kInvalidThreadId; |
177 } | 177 } |
178 | 178 |
179 } // namespace base | 179 } // namespace base |
OLD | NEW |