Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1083)

Unified Diff: base/threading/watchdog.cc

Issue 9173002: Watchdog - Added a JOINABLE state to avoid StartupTimebomb (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/watchdog.h ('k') | chrome/browser/metrics/thread_watcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/watchdog.cc
===================================================================
--- base/threading/watchdog.cc (revision 117912)
+++ base/threading/watchdog.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,33 +36,48 @@
Watchdog::Watchdog(const TimeDelta& duration,
const std::string& thread_watched_name,
bool enabled)
- : init_successful_(false),
+ : enabled_(enabled),
lock_(),
condition_variable_(&lock_),
state_(DISARMED),
duration_(duration),
thread_watched_name_(thread_watched_name),
ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)) {
- if (!enabled)
+ if (!enabled_)
return; // Don't start thread, or doing anything really.
- init_successful_ = PlatformThread::Create(0, // Default stack size.
- &delegate_,
- &handle_);
- DCHECK(init_successful_);
+ enabled_ = PlatformThread::Create(0, // Default stack size.
+ &delegate_,
+ &handle_);
+ DCHECK(enabled_);
}
// Notify watchdog thread, and wait for it to finish up.
Watchdog::~Watchdog() {
- if (!init_successful_)
+ if (!enabled_)
return;
+ if (!IsJoinable())
+ Cleanup();
+ condition_variable_.Signal();
+ PlatformThread::Join(handle_);
+}
+
+void Watchdog::Cleanup() {
+ if (!enabled_)
+ return;
{
AutoLock lock(lock_);
state_ = SHUTDOWN;
}
condition_variable_.Signal();
- PlatformThread::Join(handle_);
}
+bool Watchdog::IsJoinable() {
+ if (!enabled_)
+ return true;
+ AutoLock lock(lock_);
+ return (state_ == JOINABLE);
+}
+
void Watchdog::Arm() {
ArmAtStartTime(TimeTicks::Now());
}
@@ -105,8 +120,10 @@
AutoLock lock(watchdog_->lock_);
while (DISARMED == watchdog_->state_)
watchdog_->condition_variable_.Wait();
- if (SHUTDOWN == watchdog_->state_)
+ if (SHUTDOWN == watchdog_->state_) {
+ watchdog_->state_ = JOINABLE;
return;
+ }
DCHECK(ARMED == watchdog_->state_);
remaining_duration = watchdog_->duration_ -
(TimeTicks::Now() - watchdog_->start_time_);
« no previous file with comments | « base/threading/watchdog.h ('k') | chrome/browser/metrics/thread_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698