| 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 GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ | 5 #ifndef GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
| 6 #define GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ | 6 #define GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
| 7 | 7 |
| 8 #include "base/atomicops.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/power_monitor/power_observer.h" | 13 #include "base/power_monitor/power_observer.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "gpu/gpu_export.h" | 17 #include "gpu/gpu_export.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 // A thread that intermitently sends tasks to a group of watched message loops | 32 // A thread that intermitently sends tasks to a group of watched message loops |
| 32 // and deliberately crashes if one of them does not respond after a timeout. | 33 // and deliberately crashes if one of them does not respond after a timeout. |
| 33 class GPU_EXPORT GpuWatchdogThread | 34 class GPU_EXPORT GpuWatchdogThread |
| 34 : public base::Thread, | 35 : public base::Thread, |
| 35 public base::PowerObserver, | 36 public base::PowerObserver, |
| 36 public base::RefCountedThreadSafe<GpuWatchdogThread> { | 37 public base::RefCountedThreadSafe<GpuWatchdogThread> { |
| 37 public: | 38 public: |
| 38 static scoped_refptr<GpuWatchdogThread> Create(); | 39 static scoped_refptr<GpuWatchdogThread> Create(); |
| 39 | 40 |
| 40 // Accessible on watched thread but only modified by watchdog thread. | |
| 41 bool armed() const { return armed_; } | |
| 42 void PostAcknowledge(); | 41 void PostAcknowledge(); |
| 43 | |
| 44 void CheckArmed(); | 42 void CheckArmed(); |
| 45 | 43 |
| 46 // Must be called after a PowerMonitor has been created. Can be called from | 44 // Must be called after a PowerMonitor has been created. Can be called from |
| 47 // any thread. | 45 // any thread. |
| 48 void AddPowerObserver(); | 46 void AddPowerObserver(); |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 void Init() override; | 49 void Init() override; |
| 52 void CleanUp() override; | 50 void CleanUp() override; |
| 53 | 51 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
| 91 base::ThreadTicks GetWatchedThreadTime(); | 89 base::ThreadTicks GetWatchedThreadTime(); |
| 92 #endif | 90 #endif |
| 93 | 91 |
| 94 #if defined(USE_X11) | 92 #if defined(USE_X11) |
| 95 int GetActiveTTY() const; | 93 int GetActiveTTY() const; |
| 96 #endif | 94 #endif |
| 97 | 95 |
| 98 base::MessageLoop* watched_message_loop_; | 96 base::MessageLoop* watched_message_loop_; |
| 99 base::TimeDelta timeout_; | 97 base::TimeDelta timeout_; |
| 100 volatile bool armed_; | 98 bool armed_; |
| 101 GpuWatchdogTaskObserver task_observer_; | 99 GpuWatchdogTaskObserver task_observer_; |
| 102 | 100 |
| 101 // |awaiting_acknowledge_| is only ever read on the watched thread, but may |
| 102 // be modified on either the watched or watchdog thread. Reads/writes should |
| 103 // be careful to ensure that appropriate synchronization is used. |
| 104 base::subtle::Atomic32 awaiting_acknowledge_; |
| 105 |
| 103 // True if the watchdog should wait for a certain amount of CPU to be used | 106 // True if the watchdog should wait for a certain amount of CPU to be used |
| 104 // before killing the process. | 107 // before killing the process. |
| 105 bool use_thread_cpu_time_; | 108 bool use_thread_cpu_time_; |
| 106 | 109 |
| 107 // The number of consecutive acknowledgements that had a latency less than | 110 // The number of consecutive acknowledgements that had a latency less than |
| 108 // 50ms. | 111 // 50ms. |
| 109 int responsive_acknowledge_count_; | 112 int responsive_acknowledge_count_; |
| 110 | 113 |
| 111 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
| 112 void* watched_thread_handle_; | 115 void* watched_thread_handle_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 140 #endif | 143 #endif |
| 141 | 144 |
| 142 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; | 145 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; |
| 143 | 146 |
| 144 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | 147 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 } // namespace gpu | 150 } // namespace gpu |
| 148 | 151 |
| 149 #endif // GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ | 152 #endif // GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
| OLD | NEW |