| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_GPU_GPU_WATCHDOG_THREAD_H_ | |
| 6 #define CHROME_GPU_GPU_WATCHDOG_THREAD_H_ | |
| 7 | |
| 8 #include "base/message_loop.h" | |
| 9 #include "base/ref_counted.h" | |
| 10 #include "base/scoped_ptr.h" | |
| 11 #include "base/task.h" | |
| 12 #include "base/threading/thread.h" | |
| 13 #include "base/time.h" | |
| 14 | |
| 15 // A thread that intermitently sends tasks to a group of watched message loops | |
| 16 // and deliberately crashes if one of them does not respond after a timeout. | |
| 17 class GpuWatchdogThread : public base::Thread, | |
| 18 public base::RefCountedThreadSafe<GpuWatchdogThread> { | |
| 19 public: | |
| 20 explicit GpuWatchdogThread(int timeout); | |
| 21 virtual ~GpuWatchdogThread(); | |
| 22 | |
| 23 // Accessible on watched thread but only modified by watchdog thread. | |
| 24 bool armed() const { return armed_; } | |
| 25 void PostAcknowledge(); | |
| 26 | |
| 27 protected: | |
| 28 virtual void Init(); | |
| 29 virtual void CleanUp(); | |
| 30 | |
| 31 private: | |
| 32 | |
| 33 // An object of this type intercepts the reception and completion of all tasks | |
| 34 // on the watched thread and checks whether the watchdog is armed. | |
| 35 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver { | |
| 36 public: | |
| 37 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); | |
| 38 virtual ~GpuWatchdogTaskObserver(); | |
| 39 | |
| 40 // Implements MessageLoop::TaskObserver. | |
| 41 virtual void WillProcessTask(const Task* task); | |
| 42 virtual void DidProcessTask(const Task* task); | |
| 43 | |
| 44 private: | |
| 45 void CheckArmed(); | |
| 46 GpuWatchdogThread* watchdog_; | |
| 47 }; | |
| 48 | |
| 49 void OnAcknowledge(); | |
| 50 void OnCheck(); | |
| 51 void DeliberatelyCrashingToRecoverFromHang(); | |
| 52 void Disable(); | |
| 53 | |
| 54 int64 GetWatchedThreadTime(); | |
| 55 | |
| 56 MessageLoop* watched_message_loop_; | |
| 57 int timeout_; | |
| 58 volatile bool armed_; | |
| 59 GpuWatchdogTaskObserver task_observer_; | |
| 60 | |
| 61 #if defined(OS_WIN) | |
| 62 void* watched_thread_handle_; | |
| 63 int64 arm_cpu_time_; | |
| 64 #endif | |
| 65 | |
| 66 base::Time arm_absolute_time_; | |
| 67 | |
| 68 typedef ScopedRunnableMethodFactory<GpuWatchdogThread> MethodFactory; | |
| 69 scoped_ptr<MethodFactory> method_factory_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | |
| 72 }; | |
| 73 | |
| 74 #endif // CHROME_GPU_GPU_WATCHDOG_THREAD_H_ | |
| OLD | NEW |