summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-10-10 15:33:14 +0100
committerSteve Block <steveblock@google.com>2011-10-10 15:59:20 +0100
commitd0a07ba49f88f1e331ac5fd80f30c81d975ebd12 (patch)
tree2f8d4f486aad09345a6d4d18ee5d773b7117d559 /base
parent28480d4f48373da735986b2a75e099d3cfddab3e (diff)
downloadexternal_chromium-d0a07ba49f88f1e331ac5fd80f30c81d975ebd12.zip
external_chromium-d0a07ba49f88f1e331ac5fd80f30c81d975ebd12.tar.gz
external_chromium-d0a07ba49f88f1e331ac5fd80f30c81d975ebd12.tar.bz2
More logging in Thread to help debugging
Add a check for multiple overlapping calls to StartWithOptions() Bug: 5244039 Change-Id: Ic89b94309126cc53320c3e7973c0eea0d88fd9c4
Diffstat (limited to 'base')
-rw-r--r--base/threading/thread.cc52
-rw-r--r--base/threading/thread.h6
2 files changed, 43 insertions, 15 deletions
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index 2f10adf..ea81644 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -53,6 +53,10 @@ Thread::Thread(const char* name)
message_loop_(NULL),
thread_id_(kInvalidThreadId),
name_(name) {
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ is_starting_ = false;
+#endif
}
Thread::~Thread() {
@@ -60,31 +64,38 @@ Thread::~Thread() {
}
bool Thread::Start() {
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ LOG(INFO) << "Start(), this=" << this << ", name_=" << name_;
+#endif
return StartWithOptions(Options());
}
bool Thread::StartWithOptions(const Options& options) {
DCHECK(!message_loop_);
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ LOG(INFO) << "StartWithOptions(), this=" << this << ", name_=" << name_;
+ is_starting_lock_.Acquire();
+ CHECK(!is_starting_);
+ is_starting_ = true;
+ is_starting_lock_.Release();
+#endif
+
SetThreadWasQuitProperly(false);
StartupData startup_data(options);
#if defined(ANDROID)
// For debugging. See http://b/5244039
LOG(INFO) << "StartWithOptions() created startup_data, this=" << this
- << ", startup_data.event.IsSignaled()="
- << startup_data.event.IsSignaled();
+ << ", name_=" << name_;
#endif
startup_data_ = &startup_data;
if (!PlatformThread::Create(options.stack_size, this, &thread_)) {
DLOG(ERROR) << "failed to create thread";
-#if defined(ANDROID)
- // For debugging. See http://b/5244039
- startup_data_ = reinterpret_cast<StartupData*>(0xdeadd00d);
-#else
startup_data_ = NULL;
-#endif
return false;
}
@@ -92,8 +103,7 @@ bool Thread::StartWithOptions(const Options& options) {
#if defined(ANDROID)
// For debugging. See http://b/5244039
LOG(INFO) << "StartWithOptions() waiting for thread to start, this=" << this
- << ", startup_data.event.IsSignaled()="
- << startup_data.event.IsSignaled();
+ << ", name_=" << name_;
#endif
startup_data.event.Wait();
@@ -101,19 +111,29 @@ bool Thread::StartWithOptions(const Options& options) {
#if defined(ANDROID)
// For debugging. See http://b/5244039
LOG(INFO) << "StartWithOptions() clearing startup_data_, this=" << this
- << ", startup_data.event.IsSignaled()="
- << startup_data.event.IsSignaled();
+ << ", name_=" << name_;
startup_data_ = reinterpret_cast<StartupData*>(0xbbadbeef);
#else
startup_data_ = NULL;
#endif
started_ = true;
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ is_starting_lock_.Acquire();
+ is_starting_ = false;
+ is_starting_lock_.Release();
+#endif
+
DCHECK(message_loop_);
return true;
}
void Thread::Stop() {
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ LOG(INFO) << "Stop(), this=" << this << ", name_=" << name_;
+#endif
if (!thread_was_started())
return;
@@ -133,6 +153,10 @@ void Thread::Stop() {
started_ = false;
stopping_ = false;
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ LOG(INFO) << "Stop() done, this=" << this << ", name_=" << name_;
+#endif
}
void Thread::StopSoon() {
@@ -170,8 +194,7 @@ void Thread::ThreadMain() {
#if defined(ANDROID)
// For debugging. See http://b/5244039
LOG(INFO) << "ThreadMain() starting, this=" << this
- << ", startup_data_->event.IsSignaled()="
- << startup_data_->event.IsSignaled();
+ << ", name_=" << name_;
#endif
// The message loop for this thread.
MessageLoop message_loop(startup_data_->options.message_loop_type);
@@ -191,8 +214,7 @@ void Thread::ThreadMain() {
#if defined(ANDROID)
// For debugging. See http://b/5244039
LOG(INFO) << "ThreadMain() signalling, this=" << this
- << ", startup_data_->event.IsSignaled()="
- << startup_data_->event.IsSignaled();
+ << ", name_=" << name_;
#endif
startup_data_->event.Signal();
// startup_data_ can't be touched anymore since the starting thread is now
diff --git a/base/threading/thread.h b/base/threading/thread.h
index 034cb7d..c3516e7 100644
--- a/base/threading/thread.h
+++ b/base/threading/thread.h
@@ -185,6 +185,12 @@ class BASE_API Thread : PlatformThread::Delegate {
// The name of the thread. Used for debugging purposes.
std::string name_;
+#if defined(ANDROID)
+ // For debugging. See http://b/5244039
+ Lock is_starting_lock_;
+ bool is_starting_;
+#endif
+
friend class ThreadQuitTask;
DISALLOW_COPY_AND_ASSIGN(Thread);