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. |
@@ -55,14 +55,29 @@ |
Watchdog::~Watchdog() { |
if (!init_successful_) |
return; |
+ if (!IsJoinable()) |
+ Cleanup(); |
+ condition_variable_.Signal(); |
+ PlatformThread::Join(handle_); |
+} |
+ |
+void Watchdog::Cleanup() { |
+ if (!init_successful_) |
+ return; |
{ |
AutoLock lock(lock_); |
state_ = SHUTDOWN; |
} |
condition_variable_.Signal(); |
- PlatformThread::Join(handle_); |
} |
+bool Watchdog::IsJoinable() { |
+ if (!init_successful_) |
+ 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_); |