OLD | NEW |
1 // Copyright (c) 2010 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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // they are independent. | 52 // they are independent. |
53 static void ResetStaticData(); | 53 static void ResetStaticData(); |
54 | 54 |
55 private: | 55 private: |
56 class ThreadDelegate : public PlatformThread::Delegate { | 56 class ThreadDelegate : public PlatformThread::Delegate { |
57 public: | 57 public: |
58 explicit ThreadDelegate(Watchdog* watchdog) : watchdog_(watchdog) { | 58 explicit ThreadDelegate(Watchdog* watchdog) : watchdog_(watchdog) { |
59 } | 59 } |
60 virtual void ThreadMain(); | 60 virtual void ThreadMain(); |
61 private: | 61 private: |
| 62 void SetThreadName() const; |
| 63 |
62 Watchdog* watchdog_; | 64 Watchdog* watchdog_; |
63 | |
64 void SetThreadName() const; | |
65 }; | 65 }; |
66 | 66 |
67 enum State {ARMED, DISARMED, SHUTDOWN }; | 67 enum State {ARMED, DISARMED, SHUTDOWN }; |
68 | 68 |
69 bool init_successful_; | 69 bool init_successful_; |
70 | 70 |
71 Lock lock_; // Mutex for state_. | 71 Lock lock_; // Mutex for state_. |
72 ConditionVariable condition_variable_; | 72 ConditionVariable condition_variable_; |
73 State state_; | 73 State state_; |
74 const TimeDelta duration_; // How long after start_time_ do we alarm? | 74 const TimeDelta duration_; // How long after start_time_ do we alarm? |
(...skipping 14 matching lines...) Expand all Loading... |
89 static TimeTicks last_debugged_alarm_time_; | 89 static TimeTicks last_debugged_alarm_time_; |
90 // How long did we sit on a break in the debugger? | 90 // How long did we sit on a break in the debugger? |
91 static TimeDelta last_debugged_alarm_delay_; | 91 static TimeDelta last_debugged_alarm_delay_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(Watchdog); | 93 DISALLOW_COPY_AND_ASSIGN(Watchdog); |
94 }; | 94 }; |
95 | 95 |
96 } // namespace base | 96 } // namespace base |
97 | 97 |
98 #endif // BASE_THREADING_WATCHDOG_H_ | 98 #endif // BASE_THREADING_WATCHDOG_H_ |
OLD | NEW |