summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-21 18:49:37 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-21 18:49:37 +0000
commit06c0c06f6f2d80f3af22d3432cdf4c53b3882d08 (patch)
tree9b16d53ce990493d8a0ee8241b02173ad6434e1c /base/threading
parent3e0cf4adfeb1a9667086d15b557d093f67a97f8c (diff)
downloadchromium_src-06c0c06f6f2d80f3af22d3432cdf4c53b3882d08.zip
chromium_src-06c0c06f6f2d80f3af22d3432cdf4c53b3882d08.tar.gz
chromium_src-06c0c06f6f2d80f3af22d3432cdf4c53b3882d08.tar.bz2
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
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/thread.cc10
-rw-r--r--base/threading/thread.h6
2 files changed, 12 insertions, 4 deletions
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index d6913a7..ceaddef 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -1,4 +1,4 @@
-// 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
diff --git a/base/threading/thread.h b/base/threading/thread.h
index eb3d1c3..054a8f6 100644
--- a/base/threading/thread.h
+++ b/base/threading/thread.h
@@ -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_;