| 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/profiler/scoped_tracker.h" | |
| 11 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 13 #include "base/threading/thread_id_name_manager.h" | 12 #include "base/threading/thread_id_name_manager.h" |
| 14 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 16 | 15 |
| 17 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 18 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
| 19 #endif | 18 #endif |
| 20 | 19 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (stopping_ || !message_loop_) | 172 if (stopping_ || !message_loop_) |
| 174 return; | 173 return; |
| 175 | 174 |
| 176 stopping_ = true; | 175 stopping_ = true; |
| 177 task_runner()->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper)); | 176 task_runner()->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper)); |
| 178 } | 177 } |
| 179 | 178 |
| 180 PlatformThreadId Thread::GetThreadId() const { | 179 PlatformThreadId Thread::GetThreadId() const { |
| 181 // If the thread is created but not started yet, wait for |id_| being ready. | 180 // If the thread is created but not started yet, wait for |id_| being ready. |
| 182 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 181 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 183 // TODO(toyoshim): Remove this after a few days (crbug.com/495097) | |
| 184 tracked_objects::ScopedTracker tracking_profile( | |
| 185 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 186 "495097 base::Thread::GetThreadId")); | |
| 187 id_event_.Wait(); | 182 id_event_.Wait(); |
| 188 return id_; | 183 return id_; |
| 189 } | 184 } |
| 190 | 185 |
| 191 bool Thread::IsRunning() const { | 186 bool Thread::IsRunning() const { |
| 192 // If the thread's already started (i.e. message_loop_ is non-null) and | 187 // If the thread's already started (i.e. message_loop_ is non-null) and |
| 193 // not yet requested to stop (i.e. stopping_ is false) we can just return | 188 // not yet requested to stop (i.e. stopping_ is false) we can just return |
| 194 // true. (Note that stopping_ is touched only on the same thread that | 189 // true. (Note that stopping_ is touched only on the same thread that |
| 195 // starts / started the new thread so we need no locking here.) | 190 // starts / started the new thread so we need no locking here.) |
| 196 if (message_loop_ && !stopping_) | 191 if (message_loop_ && !stopping_) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 265 |
| 271 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 266 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
| 272 DCHECK(GetThreadWasQuitProperly()); | 267 DCHECK(GetThreadWasQuitProperly()); |
| 273 | 268 |
| 274 // We can't receive messages anymore. | 269 // We can't receive messages anymore. |
| 275 // (The message loop is destructed at the end of this block) | 270 // (The message loop is destructed at the end of this block) |
| 276 message_loop_ = NULL; | 271 message_loop_ = NULL; |
| 277 } | 272 } |
| 278 | 273 |
| 279 } // namespace base | 274 } // namespace base |
| OLD | NEW |