Chromium Code Reviews| Index: base/threading/thread.cc |
| diff --git a/base/threading/thread.cc b/base/threading/thread.cc |
| index 7bff24232e2bf2d66fda4485a4246ebae2e98332..d9af1b551c411cfaeb42a0069a7e85c2bb1804d0 100644 |
| --- a/base/threading/thread.cc |
| +++ b/base/threading/thread.cc |
| @@ -62,6 +62,7 @@ Thread::Thread(const std::string& name) |
| stopping_(false), |
| running_(false), |
| thread_(0), |
| + id_(kInvalidThreadId), |
| message_loop_(nullptr), |
| message_loop_timer_slack_(TIMER_SLACK_NONE), |
| name_(name) { |
| @@ -177,8 +178,9 @@ void Thread::StopSoon() { |
| } |
| PlatformThreadId Thread::thread_id() const { |
| - AutoLock lock(thread_lock_); |
| - return thread_.id(); |
| + CHECK_NE(kInvalidThreadId, id_); |
|
gab
2015/07/09 18:19:00
Is this really a security issue? i.e. is it worth
Takashi Toyoshima
2015/07/14 10:47:28
I see, DCHECK_NE looks better here.
|
| + AutoLock lock(id_lock_); |
| + return id_; |
| } |
| bool Thread::IsRunning() const { |
| @@ -212,6 +214,10 @@ bool Thread::GetThreadWasQuitProperly() { |
| void Thread::ThreadMain() { |
| // Complete the initialization of our Thread object. |
| + { |
| + AutoLock lock(id_lock_); |
| + id_ = PlatformThread::CurrentId(); |
| + } |
| PlatformThread::SetName(name_.c_str()); |
| ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. |
| @@ -231,10 +237,6 @@ void Thread::ThreadMain() { |
| } |
| #endif |
| - // Make sure the thread_id() returns current thread. |
| - // (This internally acquires lock against PlatformThread::Create) |
| - DCHECK_EQ(thread_id(), PlatformThread::CurrentId()); |
| - |
| // Let the thread do extra initialization. |
| Init(); |