| Index: base/threading/thread.cc
|
| diff --git a/base/threading/thread.cc b/base/threading/thread.cc
|
| index 7bff24232e2bf2d66fda4485a4246ebae2e98332..ad6133286434f1d57ae9089851b1bfaacccc3e9b 100644
|
| --- a/base/threading/thread.cc
|
| +++ b/base/threading/thread.cc
|
| @@ -62,6 +62,8 @@ Thread::Thread(const std::string& name)
|
| stopping_(false),
|
| running_(false),
|
| thread_(0),
|
| + id_(kInvalidThreadId),
|
| + id_event_(true, false),
|
| message_loop_(nullptr),
|
| message_loop_timer_slack_(TIMER_SLACK_NONE),
|
| name_(name) {
|
| @@ -87,6 +89,9 @@ bool Thread::StartWithOptions(const Options& options) {
|
| (options.message_loop_type == MessageLoop::TYPE_UI));
|
| #endif
|
|
|
| + id_event_.Reset();
|
| + id_ = kInvalidThreadId;
|
| +
|
| SetThreadWasQuitProperly(false);
|
|
|
| MessageLoop::Type type = options.message_loop_type;
|
| @@ -177,8 +182,9 @@ void Thread::StopSoon() {
|
| }
|
|
|
| PlatformThreadId Thread::thread_id() const {
|
| - AutoLock lock(thread_lock_);
|
| - return thread_.id();
|
| + base::ThreadRestrictions::ScopedAllowWait allow_wait;
|
| + id_event_.Wait();
|
| + return id_;
|
| }
|
|
|
| bool Thread::IsRunning() const {
|
| @@ -211,6 +217,11 @@ bool Thread::GetThreadWasQuitProperly() {
|
| }
|
|
|
| void Thread::ThreadMain() {
|
| + // Make thread_id() available first since it could be called any place.
|
| + id_ = PlatformThread::CurrentId();
|
| + DCHECK_NE(kInvalidThreadId, id_);
|
| + id_event_.Signal();
|
| +
|
| // Complete the initialization of our Thread object.
|
| PlatformThread::SetName(name_.c_str());
|
| ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
|
| @@ -231,10 +242,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();
|
|
|
|
|