| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // The Watchdog class creates a second thread that can Alarm if a specific | 5 // The Watchdog class creates a second thread that can Alarm if a specific |
| 6 // duration of time passes without proper attention. The duration of time is | 6 // duration of time passes without proper attention. The duration of time is |
| 7 // specified at construction time. The Watchdog may be used many times by | 7 // specified at construction time. The Watchdog may be used many times by |
| 8 // simply calling Arm() (to start timing) and Disarm() (to reset the timer). | 8 // simply calling Arm() (to start timing) and Disarm() (to reset the timer). |
| 9 // The Watchdog is typically used under a debugger, where the stack traces on | 9 // The Watchdog is typically used under a debugger, where the stack traces on |
| 10 // other threads can be examined if/when the Watchdog alarms. | 10 // other threads can be examined if/when the Watchdog alarms. |
| 11 | 11 |
| 12 // Some watchdogs will be enabled or disabled via command line switches. To | 12 // Some watchdogs will be enabled or disabled via command line switches. To |
| 13 // facilitate such code, an "enabled" argument for the constuctor can be used | 13 // facilitate such code, an "enabled" argument for the constuctor can be used |
| 14 // to permanently disable the watchdog. Disabled watchdogs don't even spawn | 14 // to permanently disable the watchdog. Disabled watchdogs don't even spawn |
| 15 // a second thread, and their methods call (Arm() and Disarm()) return very | 15 // a second thread, and their methods call (Arm() and Disarm()) return very |
| 16 // quickly. | 16 // quickly. |
| 17 | 17 |
| 18 #ifndef BASE_THREADING_WATCHDOG_H_ | 18 #ifndef BASE_THREADING_WATCHDOG_H_ |
| 19 #define BASE_THREADING_WATCHDOG_H_ | 19 #define BASE_THREADING_WATCHDOG_H_ |
| 20 #pragma once | 20 #pragma once |
| 21 | 21 |
| 22 #include <string> | 22 #include <string> |
| 23 | 23 |
| 24 #include "base/base_api.h" | 24 #include "base/base_export.h" |
| 25 #include "base/synchronization/condition_variable.h" | 25 #include "base/synchronization/condition_variable.h" |
| 26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
| 27 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
| 28 #include "base/time.h" | 28 #include "base/time.h" |
| 29 | 29 |
| 30 namespace base { | 30 namespace base { |
| 31 | 31 |
| 32 class BASE_API Watchdog { | 32 class BASE_EXPORT Watchdog { |
| 33 public: | 33 public: |
| 34 // Constructor specifies how long the Watchdog will wait before alarming. | 34 // Constructor specifies how long the Watchdog will wait before alarming. |
| 35 Watchdog(const TimeDelta& duration, | 35 Watchdog(const TimeDelta& duration, |
| 36 const std::string& thread_watched_name, | 36 const std::string& thread_watched_name, |
| 37 bool enabled); | 37 bool enabled); |
| 38 virtual ~Watchdog(); | 38 virtual ~Watchdog(); |
| 39 | 39 |
| 40 // Start timing, and alarm when time expires (unless we're disarm()ed.) | 40 // Start timing, and alarm when time expires (unless we're disarm()ed.) |
| 41 void Arm(); // Arm starting now. | 41 void Arm(); // Arm starting now. |
| 42 void ArmSomeTimeDeltaAgo(const TimeDelta& time_delta); | 42 void ArmSomeTimeDeltaAgo(const TimeDelta& time_delta); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 static TimeTicks last_debugged_alarm_time_; | 90 static TimeTicks last_debugged_alarm_time_; |
| 91 // How long did we sit on a break in the debugger? | 91 // How long did we sit on a break in the debugger? |
| 92 static TimeDelta last_debugged_alarm_delay_; | 92 static TimeDelta last_debugged_alarm_delay_; |
| 93 | 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(Watchdog); | 94 DISALLOW_COPY_AND_ASSIGN(Watchdog); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // namespace base | 97 } // namespace base |
| 98 | 98 |
| 99 #endif // BASE_THREADING_WATCHDOG_H_ | 99 #endif // BASE_THREADING_WATCHDOG_H_ |
| OLD | NEW |