Chromium Code Reviews| Index: base/threading/watchdog.cc |
| diff --git a/base/threading/watchdog.cc b/base/threading/watchdog.cc |
| index cd215780c8b74372c6bda3f8be5ba456544100cb..2660f1b2f7d00ed8da6ad9770ae8b66cd027e82f 100644 |
| --- a/base/threading/watchdog.cc |
| +++ b/base/threading/watchdog.cc |
| @@ -5,11 +5,29 @@ |
| #include "base/threading/watchdog.h" |
| #include "base/compiler_specific.h" |
| +#include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/threading/platform_thread.h" |
| namespace base { |
| +namespace { |
| + |
| +// When the debugger breaks (when we alarm), all the other alarms that are |
| +// armed will expire (also alarm). To diminish this effect, we track any |
| +// delay due to debugger breaks, and we *try* to adjust the effective start |
| +// time of other alarms to step past the debugging break. |
| +// Without this safety net, any alarm will typically trigger a host of follow |
| +// on alarms from callers that specify old times. |
| +LazyInstance<Lock> g_static_lock_( // Lock for access of static data... |
|
Mark Mentovai
2011/11/03 22:11:03
Can you write this line like a human being?
|
| + LINKER_INITIALIZED); |
| +// When did we last alarm and get stuck (for a while) in a debugger? |
|
Mark Mentovai
2011/11/03 22:11:03
Put a blank line before me.
|
| +TimeTicks g_last_debugged_alarm_time_; |
| +// How long did we sit on a break in the debugger? |
|
Mark Mentovai
2011/11/03 22:11:03
Me too.
|
| +TimeDelta g_last_debugged_alarm_delay_; |
|
Mark Mentovai
2011/11/03 22:11:03
None of these should have trailing underscores any
|
| + |
| +} // namespace |
| + |
| // Start thread running in a Disarmed state. |
| Watchdog::Watchdog(const TimeDelta& duration, |
| const std::string& thread_watched_name, |
| @@ -96,12 +114,12 @@ void Watchdog::ThreadDelegate::ThreadMain() { |
| // We overslept, so this seems like a real alarm. |
| // Watch out for a user that stopped the debugger on a different alarm! |
| { |
| - AutoLock static_lock(static_lock_); |
| - if (last_debugged_alarm_time_ > watchdog_->start_time_) { |
| + AutoLock static_lock(*g_static_lock_.Pointer()); |
| + if (g_last_debugged_alarm_time_ > watchdog_->start_time_) { |
| // False alarm: we started our clock before the debugger break (last |
| // alarm time). |
| - watchdog_->start_time_ += last_debugged_alarm_delay_; |
| - if (last_debugged_alarm_time_ > watchdog_->start_time_) |
| + watchdog_->start_time_ += g_last_debugged_alarm_delay_; |
| + if (g_last_debugged_alarm_time_ > watchdog_->start_time_) |
| // Too many alarms must have taken place. |
| watchdog_->state_ = DISARMED; |
| continue; |
| @@ -114,10 +132,10 @@ void Watchdog::ThreadDelegate::ThreadMain() { |
| if (last_alarm_delay <= TimeDelta::FromMilliseconds(2)) |
| continue; |
| // Ignore race of two alarms/breaks going off at roughly the same time. |
| - AutoLock static_lock(static_lock_); |
| + AutoLock static_lock(*g_static_lock_.Pointer()); |
| // This was a real debugger break. |
| - last_debugged_alarm_time_ = last_alarm_time; |
| - last_debugged_alarm_delay_ = last_alarm_delay; |
| + g_last_debugged_alarm_time_ = last_alarm_time; |
| + g_last_debugged_alarm_delay_ = last_alarm_delay; |
| } |
| } |
| @@ -129,16 +147,9 @@ void Watchdog::ThreadDelegate::SetThreadName() const { |
| // static |
| void Watchdog::ResetStaticData() { |
| - AutoLock lock(static_lock_); |
| - last_debugged_alarm_time_ = TimeTicks(); |
| - last_debugged_alarm_delay_ = TimeDelta(); |
| + AutoLock lock(*g_static_lock_.Pointer()); |
| + g_last_debugged_alarm_time_ = TimeTicks(); |
| + g_last_debugged_alarm_delay_ = TimeDelta(); |
| } |
| -// static |
| -Lock Watchdog::static_lock_; // Lock for access of static data... |
| -// static |
| -TimeTicks Watchdog::last_debugged_alarm_time_ = TimeTicks(); |
| -// static |
| -TimeDelta Watchdog::last_debugged_alarm_delay_; |
| - |
| } // namespace base |