OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 5 #ifndef CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/common/gpu/gpu_watchdog.h" | 14 #include "content/common/gpu/gpu_watchdog.h" |
15 | 15 |
16 // A thread that intermitently sends tasks to a group of watched message loops | 16 // A thread that intermitently sends tasks to a group of watched message loops |
17 // and deliberately crashes if one of them does not respond after a timeout. | 17 // and deliberately crashes if one of them does not respond after a timeout. |
18 class GpuWatchdogThread : public base::Thread, | 18 class GpuWatchdogThread : public base::Thread, |
19 public GpuWatchdog, | 19 public GpuWatchdog, |
20 public base::RefCountedThreadSafe<GpuWatchdogThread> { | 20 public base::RefCountedThreadSafe<GpuWatchdogThread> { |
21 public: | 21 public: |
22 explicit GpuWatchdogThread(int timeout); | 22 explicit GpuWatchdogThread(int timeout); |
23 virtual ~GpuWatchdogThread(); | |
24 | 23 |
25 // Accessible on watched thread but only modified by watchdog thread. | 24 // Accessible on watched thread but only modified by watchdog thread. |
26 bool armed() const { return armed_; } | 25 bool armed() const { return armed_; } |
27 void PostAcknowledge(); | 26 void PostAcknowledge(); |
28 | 27 |
29 // Implement GpuWatchdog. | 28 // Implement GpuWatchdog. |
30 virtual void CheckArmed() OVERRIDE; | 29 virtual void CheckArmed() OVERRIDE; |
31 | 30 |
32 protected: | 31 protected: |
33 virtual void Init() OVERRIDE; | 32 virtual void Init() OVERRIDE; |
34 virtual void CleanUp() OVERRIDE; | 33 virtual void CleanUp() OVERRIDE; |
35 | 34 |
36 private: | 35 private: |
| 36 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; |
37 | 37 |
38 // An object of this type intercepts the reception and completion of all tasks | 38 // An object of this type intercepts the reception and completion of all tasks |
39 // on the watched thread and checks whether the watchdog is armed. | 39 // on the watched thread and checks whether the watchdog is armed. |
40 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver { | 40 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver { |
41 public: | 41 public: |
42 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); | 42 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); |
43 virtual ~GpuWatchdogTaskObserver(); | 43 virtual ~GpuWatchdogTaskObserver(); |
44 | 44 |
45 // Implements MessageLoop::TaskObserver. | 45 // Implements MessageLoop::TaskObserver. |
46 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE; | 46 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE; |
47 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE; | 47 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE; |
48 | 48 |
49 private: | 49 private: |
50 GpuWatchdogThread* watchdog_; | 50 GpuWatchdogThread* watchdog_; |
51 }; | 51 }; |
52 | 52 |
| 53 virtual ~GpuWatchdogThread(); |
| 54 |
53 void OnAcknowledge(); | 55 void OnAcknowledge(); |
54 void OnCheck(); | 56 void OnCheck(); |
55 void DeliberatelyTerminateToRecoverFromHang(); | 57 void DeliberatelyTerminateToRecoverFromHang(); |
56 void Disable(); | |
57 | 58 |
| 59 #if defined(OS_WIN) |
58 base::TimeDelta GetWatchedThreadTime(); | 60 base::TimeDelta GetWatchedThreadTime(); |
| 61 #endif |
59 | 62 |
60 MessageLoop* watched_message_loop_; | 63 MessageLoop* watched_message_loop_; |
61 base::TimeDelta timeout_; | 64 base::TimeDelta timeout_; |
62 volatile bool armed_; | 65 volatile bool armed_; |
63 GpuWatchdogTaskObserver task_observer_; | 66 GpuWatchdogTaskObserver task_observer_; |
64 | 67 |
65 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
66 void* watched_thread_handle_; | 69 void* watched_thread_handle_; |
67 base::TimeDelta arm_cpu_time_; | 70 base::TimeDelta arm_cpu_time_; |
68 #endif | 71 #endif |
69 | 72 |
70 base::Time arm_absolute_time_; | 73 base::Time arm_absolute_time_; |
71 | 74 |
72 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; | 75 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; |
73 | 76 |
74 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | 77 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); |
75 }; | 78 }; |
76 | 79 |
77 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 80 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
OLD | NEW |