Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include "chrome/gpu/gpu_watchdog_thread.h" | 9 #include "chrome/gpu/gpu_watchdog_thread.h" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 method_factory_.reset(new MethodFactory(this)); | 52 method_factory_.reset(new MethodFactory(this)); |
| 53 | 53 |
| 54 // Schedule the first check. | 54 // Schedule the first check. |
| 55 OnCheck(); | 55 OnCheck(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void GpuWatchdogThread::CleanUp() { | 58 void GpuWatchdogThread::CleanUp() { |
| 59 // The method factory must be destroyed on the watchdog thread. | 59 // The method factory must be destroyed on the watchdog thread. |
| 60 method_factory_->RevokeAll(); | 60 method_factory_->RevokeAll(); |
| 61 method_factory_.reset(); | 61 method_factory_.reset(); |
| 62 | |
| 63 // Prevent any more delayed tasks from being posted. | |
| 64 watched_message_loop_ = NULL; | |
|
apatrick_chromium
2010/11/29 22:00:14
I don't think this was actually needed.
| |
| 65 } | 62 } |
| 66 | 63 |
| 67 GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver( | 64 GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver( |
| 68 GpuWatchdogThread* watchdog) | 65 GpuWatchdogThread* watchdog) |
| 69 : watchdog_(watchdog) { | 66 : watchdog_(watchdog) { |
| 70 } | 67 } |
| 71 | 68 |
| 72 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() { | 69 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() { |
| 73 } | 70 } |
| 74 | 71 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 99 // watched thread to see armed_ being true multiple times before | 96 // watched thread to see armed_ being true multiple times before |
| 100 // the OnAcknowledge task is run on the watchdog thread. | 97 // the OnAcknowledge task is run on the watchdog thread. |
| 101 if (!armed_) | 98 if (!armed_) |
| 102 return; | 99 return; |
| 103 | 100 |
| 104 // Revoke any pending OnExit. | 101 // Revoke any pending OnExit. |
| 105 method_factory_->RevokeAll(); | 102 method_factory_->RevokeAll(); |
| 106 armed_ = false; | 103 armed_ = false; |
| 107 | 104 |
| 108 // The monitored thread has responded. Post a task to check it again. | 105 // The monitored thread has responded. Post a task to check it again. |
| 109 if (watched_message_loop_) { | 106 message_loop()->PostDelayedTask( |
| 110 message_loop()->PostDelayedTask( | 107 FROM_HERE, |
| 111 FROM_HERE, | 108 method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnCheck), |
| 112 method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnCheck), | 109 kCheckPeriod); |
| 113 kCheckPeriod); | |
| 114 } | |
| 115 } | 110 } |
| 116 | 111 |
| 117 void GpuWatchdogThread::OnCheck() { | 112 void GpuWatchdogThread::OnCheck() { |
| 118 if (watched_message_loop_) { | 113 // Must set armed before posting the task. This task might be the only task |
| 119 // Must set armed before posting the task. This task might be the only task | 114 // that will activate the TaskObserver on the watched thread and it must not |
| 120 // that will activate the TaskObserver on the watched thread and it must not | 115 // miss the false -> true transition. |
| 121 // miss the false -> true transition. | 116 armed_ = true; |
| 122 armed_ = true; | |
| 123 | 117 |
| 124 // Post a task to the monitored thread that does nothing but wake up the | 118 // Post a task to the monitored thread that does nothing but wake up the |
| 125 // TaskObserver. Any other tasks that are pending on the watched thread will | 119 // TaskObserver. Any other tasks that are pending on the watched thread will |
| 126 // also wake up the observer. This simply ensures there is at least one. | 120 // also wake up the observer. This simply ensures there is at least one. |
| 127 watched_message_loop_->PostTask( | 121 watched_message_loop_->PostTask( |
| 128 FROM_HERE, | 122 FROM_HERE, |
| 129 NewRunnableFunction(DoNothing)); | 123 NewRunnableFunction(DoNothing)); |
| 130 | 124 |
| 131 // Post a task to the watchdog thread to exit if the monitored thread does | 125 // Post a task to the watchdog thread to exit if the monitored thread does |
| 132 // not respond in time. | 126 // not respond in time. |
| 133 message_loop()->PostDelayedTask( | 127 message_loop()->PostDelayedTask( |
| 134 FROM_HERE, | 128 FROM_HERE, |
| 135 method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnExit), | 129 method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnExit), |
| 136 timeout_); | 130 timeout_); |
| 137 } | |
| 138 } | 131 } |
| 139 | 132 |
| 140 // Use the --disable-gpu-watchdog command line switch to disable this. | 133 // Use the --disable-gpu-watchdog command line switch to disable this. |
| 141 void GpuWatchdogThread::OnExit() { | 134 void GpuWatchdogThread::OnExit() { |
| 142 // Make sure the timeout period is on the stack before crashing. | 135 // Make sure the timeout period is on the stack before crashing. |
| 143 volatile int timeout = timeout_; | 136 volatile int timeout = timeout_; |
| 144 | 137 |
| 145 // For minimal developer annoyance, don't keep crashing. | 138 // For minimal developer annoyance, don't keep crashing. |
| 146 static bool crashed = false; | 139 static bool crashed = false; |
| 147 if (crashed) | 140 if (crashed) |
| 148 return; | 141 return; |
| 149 | 142 |
| 150 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
| 151 if (IsDebuggerPresent()) | 144 if (IsDebuggerPresent()) |
| 152 return; | 145 return; |
| 153 #endif | 146 #endif |
| 154 | 147 |
| 155 LOG(ERROR) << "The GPU process hung. Restarting after " | 148 LOG(ERROR) << "The GPU process hung. Restarting after " |
| 156 << timeout_ << " seconds."; | 149 << timeout_ << " seconds."; |
| 157 | 150 |
| 158 volatile int* null_pointer = NULL; | 151 volatile int* null_pointer = NULL; |
| 159 *null_pointer = timeout; | 152 *null_pointer = timeout; |
| 160 | 153 |
| 161 crashed = true; | 154 crashed = true; |
| 162 } | 155 } |
| OLD | NEW |