summaryrefslogtreecommitdiffstats
path: root/base/thread.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 03:08:44 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 03:08:44 +0000
commit2984008f7136500a2831160f72846b94640b37ff (patch)
treeee92610da0b816c419b79f44000ee6752aabb037 /base/thread.cc
parent3f6d3a27d274d2f71a3c94e711698447f8a3993e (diff)
downloadchromium_src-2984008f7136500a2831160f72846b94640b37ff.zip
chromium_src-2984008f7136500a2831160f72846b94640b37ff.tar.gz
chromium_src-2984008f7136500a2831160f72846b94640b37ff.tar.bz2
Revert 43127 [It resulted in a free memory write because of a consumer that was relying on the old ordering (BUG=39932).]
Don't call Thread::CleanUp() before the MessageLoop destruction observers have run. This is consistent with the comment for Thread::CleanUp(), which says it runs after the message loop has "stopped". Certain consumers depend on this ordering to avoid accessing variables which are deleted by Thread::CleanUp(). BUG=39723 TEST=ThreadTest.CleanUp Review URL: http://codereview.chromium.org/1540002 TBR=eroman@chromium.org Review URL: http://codereview.chromium.org/1517006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread.cc')
-rw-r--r--base/thread.cc44
1 files changed, 20 insertions, 24 deletions
diff --git a/base/thread.cc b/base/thread.cc
index e916f2c..aeaa0a1 100644
--- a/base/thread.cc
+++ b/base/thread.cc
@@ -35,7 +35,7 @@ struct Thread::StartupData {
event(false, false) {}
};
-Thread::Thread(const char* name)
+Thread::Thread(const char *name)
: stopping_(false),
startup_data_(NULL),
thread_(0),
@@ -134,30 +134,25 @@ void Thread::Run(MessageLoop* message_loop) {
}
void Thread::ThreadMain() {
- {
- // The message loop for this thread.
- MessageLoop message_loop(startup_data_->options.message_loop_type);
-
- // Complete the initialization of our Thread object.
- thread_id_ = PlatformThread::CurrentId();
- PlatformThread::SetName(name_.c_str());
- ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
- message_loop.set_thread_name(name_);
- message_loop_ = &message_loop;
-
- // Let the thread do extra initialization.
- // Let's do this before signaling we are started.
- Init();
-
- startup_data_->event.Signal();
- // startup_data_ can't be touched anymore since the starting thread is now
- // unlocked.
-
- Run(message_loop_);
- // Destroy |message_loop| upon leaving this scope.
- }
+ // The message loop for this thread.
+ MessageLoop message_loop(startup_data_->options.message_loop_type);
- message_loop_ = NULL;
+ // Complete the initialization of our Thread object.
+ thread_id_ = PlatformThread::CurrentId();
+ PlatformThread::SetName(name_.c_str());
+ ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
+ message_loop.set_thread_name(name_);
+ message_loop_ = &message_loop;
+
+ // Let the thread do extra initialization.
+ // Let's do this before signaling we are started.
+ Init();
+
+ startup_data_->event.Signal();
+ // startup_data_ can't be touched anymore since the starting thread is now
+ // unlocked.
+
+ Run(message_loop_);
// Let the thread do extra cleanup.
CleanUp();
@@ -166,6 +161,7 @@ void Thread::ThreadMain() {
DCHECK(GetThreadWasQuitProperly());
// We can't receive messages anymore.
+ message_loop_ = NULL;
thread_id_ = 0;
}