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