| 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/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.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 | 16 |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 17 #include "base/win/scoped_com_initializer.h" | 18 #include "base/win/scoped_com_initializer.h" |
| 18 #endif | 19 #endif |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // We should only be called on the same thread that started us. | 156 // We should only be called on the same thread that started us. |
| 156 | 157 |
| 157 // Reading thread_id_ without a lock can lead to a benign data race | 158 // Reading thread_id_ without a lock can lead to a benign data race |
| 158 // with ThreadMain, so we annotate it to stay silent under ThreadSanitizer. | 159 // with ThreadMain, so we annotate it to stay silent under ThreadSanitizer. |
| 159 DCHECK_NE(ANNOTATE_UNPROTECTED_READ(thread_id_), PlatformThread::CurrentId()); | 160 DCHECK_NE(ANNOTATE_UNPROTECTED_READ(thread_id_), PlatformThread::CurrentId()); |
| 160 | 161 |
| 161 if (stopping_ || !message_loop_) | 162 if (stopping_ || !message_loop_) |
| 162 return; | 163 return; |
| 163 | 164 |
| 164 stopping_ = true; | 165 stopping_ = true; |
| 165 message_loop_->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper)); | 166 task_runner()->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool Thread::IsRunning() const { | 169 bool Thread::IsRunning() const { |
| 169 return running_; | 170 return running_; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void Thread::SetPriority(ThreadPriority priority) { | 173 void Thread::SetPriority(ThreadPriority priority) { |
| 173 // The thread must be started (and id known) for this to be | 174 // The thread must be started (and id known) for this to be |
| 174 // compatible with all platforms. | 175 // compatible with all platforms. |
| 175 DCHECK_NE(thread_id_, kInvalidThreadId); | 176 DCHECK_NE(thread_id_, kInvalidThreadId); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 244 |
| 244 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 245 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
| 245 DCHECK(GetThreadWasQuitProperly()); | 246 DCHECK(GetThreadWasQuitProperly()); |
| 246 | 247 |
| 247 // We can't receive messages anymore. | 248 // We can't receive messages anymore. |
| 248 message_loop_ = NULL; | 249 message_loop_ = NULL; |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 252 } // namespace base | 253 } // namespace base |
| OLD | NEW |