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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 owning_sequence_checker_.DetachFromSequence(); | 218 owning_sequence_checker_.DetachFromSequence(); |
219 } | 219 } |
220 | 220 |
221 PlatformThreadId Thread::GetThreadId() const { | 221 PlatformThreadId Thread::GetThreadId() const { |
222 // If the thread is created but not started yet, wait for |id_| being ready. | 222 // If the thread is created but not started yet, wait for |id_| being ready. |
223 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 223 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
224 id_event_.Wait(); | 224 id_event_.Wait(); |
225 return id_; | 225 return id_; |
226 } | 226 } |
227 | 227 |
| 228 PlatformThreadHandle Thread::GetThreadHandle() const { |
| 229 AutoLock lock(thread_lock_); |
| 230 return thread_; |
| 231 } |
| 232 |
228 bool Thread::IsRunning() const { | 233 bool Thread::IsRunning() const { |
229 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and | 234 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and |
230 // enable this check. | 235 // enable this check. |
231 // DCHECK(owning_sequence_checker_.CalledOnValidSequence()); | 236 // DCHECK(owning_sequence_checker_.CalledOnValidSequence()); |
232 | 237 |
233 // If the thread's already started (i.e. |message_loop_| is non-null) and not | 238 // If the thread's already started (i.e. |message_loop_| is non-null) and not |
234 // yet requested to stop (i.e. |stopping_| is false) we can just return true. | 239 // yet requested to stop (i.e. |stopping_| is false) we can just return true. |
235 // (Note that |stopping_| is touched only on the same sequence that starts / | 240 // (Note that |stopping_| is touched only on the same sequence that starts / |
236 // started the new thread so we need no locking here.) | 241 // started the new thread so we need no locking here.) |
237 if (message_loop_ && !stopping_) | 242 if (message_loop_ && !stopping_) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 run_loop_ = nullptr; | 362 run_loop_ = nullptr; |
358 } | 363 } |
359 | 364 |
360 void Thread::ThreadQuitHelper() { | 365 void Thread::ThreadQuitHelper() { |
361 DCHECK(run_loop_); | 366 DCHECK(run_loop_); |
362 run_loop_->QuitWhenIdle(); | 367 run_loop_->QuitWhenIdle(); |
363 SetThreadWasQuitProperly(true); | 368 SetThreadWasQuitProperly(true); |
364 } | 369 } |
365 | 370 |
366 } // namespace base | 371 } // namespace base |
OLD | NEW |