diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 05:32:38 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 05:32:38 +0000 |
commit | a0297bd51972f4bb0a1396979d57c78c015dd508 (patch) | |
tree | 0cef761002084a797cc4c8c8fda9fbe07117faea /base | |
parent | b7243c40f2c0e4742843d56d0a46c3d5ba2008d1 (diff) | |
download | chromium_src-a0297bd51972f4bb0a1396979d57c78c015dd508.zip chromium_src-a0297bd51972f4bb0a1396979d57c78c015dd508.tar.gz chromium_src-a0297bd51972f4bb0a1396979d57c78c015dd508.tar.bz2 |
Fix an issue in Thread class where we initialize a pointer, which
is a class member, with stack variable and keep its value.
BUG=48772
TEST=none
Review URL: http://codereview.chromium.org/3045008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53438 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/thread.cc | 11 | ||||
-rw-r--r-- | base/thread.h | 7 |
2 files changed, 12 insertions, 6 deletions
diff --git a/base/thread.cc b/base/thread.cc index 97f9599..82b5cf9 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -36,7 +36,8 @@ struct Thread::StartupData { }; Thread::Thread(const char* name) - : stopping_(false), + : started_(false), + stopping_(false), startup_data_(NULL), thread_(0), message_loop_(NULL), @@ -85,13 +86,17 @@ bool Thread::StartWithOptions(const Options& options) { if (!PlatformThread::Create(options.stack_size, this, &thread_)) { DLOG(ERROR) << "failed to create thread"; - startup_data_ = NULL; // Record that we failed to start. + startup_data_ = NULL; return false; } // Wait for the thread to start and initialize message_loop_ startup_data.event.Wait(); + // set it to NULL so we don't keep a pointer to some object on the stack. + startup_data_ = NULL; + started_ = true; + DCHECK(message_loop_); return true; } @@ -113,7 +118,7 @@ void Thread::Stop() { DCHECK(!message_loop_); // The thread no longer needs to be joined. - startup_data_ = NULL; + started_ = false; stopping_ = false; } diff --git a/base/thread.h b/base/thread.h index b5a87eb..351a671 100644 --- a/base/thread.h +++ b/base/thread.h @@ -154,9 +154,10 @@ class Thread : PlatformThread::Delegate { // PlatformThread::Delegate methods: virtual void ThreadMain(); - // We piggy-back on the startup_data_ member to know if we successfully - // started the thread. This way we know that we need to call Join. - bool thread_was_started() const { return startup_data_ != NULL; } + bool thread_was_started() const { return started_; } + + // Whether we successfully started the thread. + bool started_; // If true, we're in the middle of stopping, and shouldn't access // |message_loop_|. It may non-NULL and invalid. |