summaryrefslogtreecommitdiffstats
path: root/base/thread.cc
diff options
context:
space:
mode:
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;
}