Commit 06c0c06f authored by rvargas@google.com's avatar rvargas@google.com

Base: Don't overwrite the thread id when ThreadMain exits. There's

no need to do that, and it makes debugging easier to have the value.

Change the logic of IsRunning() to use a dedicated member variable 
instead of overloading the thread id. 

BUG=127931
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10399097

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138119 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e0cf4ad
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -47,6 +47,7 @@ struct Thread::StartupData {
Thread::Thread(const char* name)
: started_(false),
stopping_(false),
running_(false),
startup_data_(NULL),
thread_(0),
message_loop_(NULL),
......@@ -124,6 +125,10 @@ void Thread::StopSoon() {
message_loop_->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper));
}
bool Thread::IsRunning() const {
return running_;
}
void Thread::Run(MessageLoop* message_loop) {
message_loop->Run();
}
......@@ -160,7 +165,9 @@ void Thread::ThreadMain() {
// startup_data_ can't be touched anymore since the starting thread is now
// unlocked.
running_ = true;
Run(message_loop_);
running_ = false;
// Let the thread do extra cleanup.
CleanUp();
......@@ -171,7 +178,6 @@ void Thread::ThreadMain() {
// We can't receive messages anymore.
message_loop_ = NULL;
}
thread_id_ = kInvalidThreadId;
}
} // namespace base
......@@ -131,8 +131,7 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
PlatformThreadId thread_id() const { return thread_id_; }
// Returns true if the thread has been started, and not yet stopped.
// When a thread is running, |thread_id_| is a valid id.
bool IsRunning() const { return thread_id_ != kInvalidThreadId; }
bool IsRunning() const;
protected:
// Called just prior to starting the message loop
......@@ -164,6 +163,9 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// |message_loop_|. It may non-NULL and invalid.
bool stopping_;
// True while inside of Run().
bool running_;
// Used to pass data to ThreadMain.
struct StartupData;
StartupData* startup_data_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment