summaryrefslogtreecommitdiffstats
path: root/base/thread.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/thread.cc')
-rw-r--r--base/thread.cc29
1 files changed, 11 insertions, 18 deletions
diff --git a/base/thread.cc b/base/thread.cc
index dcda330..5fc8678 100644
--- a/base/thread.cc
+++ b/base/thread.cc
@@ -35,7 +35,8 @@ struct Thread::StartupData {
};
Thread::Thread(const char *name)
- : startup_data_(NULL),
+ : stopping_(false),
+ startup_data_(NULL),
thread_(0),
message_loop_(NULL),
thread_id_(0),
@@ -98,40 +99,32 @@ void Thread::Stop() {
if (!thread_was_started())
return;
- // We should only be called on the same thread that started us.
- DCHECK_NE(thread_id_, PlatformThread::CurrentId());
-
- // StopSoon may have already been called.
- if (message_loop_)
- message_loop_->PostTask(FROM_HERE, new ThreadQuitTask());
+ StopSoon();
- // Wait for the thread to exit. It should already have terminated but make
- // sure this assumption is valid.
+ // Wait for the thread to exit.
//
// TODO(darin): Unfortunately, we need to keep message_loop_ around until
// the thread exits. Some consumers are abusing the API. Make them stop.
//
PlatformThread::Join(thread_);
- // The thread can't receive messages anymore.
- message_loop_ = NULL;
+ // The thread should NULL message_loop_ on exit.
+ DCHECK(!message_loop_);
// The thread no longer needs to be joined.
startup_data_ = NULL;
+
+ stopping_ = false;
}
void Thread::StopSoon() {
- if (!message_loop_)
- return;
-
// We should only be called on the same thread that started us.
DCHECK_NE(thread_id_, PlatformThread::CurrentId());
- // We had better have a message loop at this point! If we do not, then it
- // most likely means that the thread terminated unexpectedly, probably due
- // to someone calling Quit() on our message loop directly.
- DCHECK(message_loop_);
+ if (!message_loop_ || stopping_)
+ return;
+ stopping_ = true;
message_loop_->PostTask(FROM_HERE, new ThreadQuitTask());
}