| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/renderer/devtools/devtools_cpu_throttler.h" | 5 #include "content/renderer/devtools/devtools_cpu_throttler.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/synchronization/cancellation_flag.h" | 9 #include "base/synchronization/cancellation_flag.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 #ifdef USE_SIGNALS | 61 #ifdef USE_SIGNALS |
| 62 bool CPUThrottlingThread::signal_handler_installed_; | 62 bool CPUThrottlingThread::signal_handler_installed_; |
| 63 struct sigaction CPUThrottlingThread::old_signal_handler_; | 63 struct sigaction CPUThrottlingThread::old_signal_handler_; |
| 64 Atomic32 CPUThrottlingThread::suspended_; | 64 Atomic32 CPUThrottlingThread::suspended_; |
| 65 #endif | 65 #endif |
| 66 Atomic32 CPUThrottlingThread::thread_exists_; | 66 Atomic32 CPUThrottlingThread::thread_exists_; |
| 67 | 67 |
| 68 CPUThrottlingThread::CPUThrottlingThread(double rate) | 68 CPUThrottlingThread::CPUThrottlingThread(double rate) |
| 69 #ifdef OS_WIN |
| 70 : throttled_thread_handle_( |
| 71 ::OpenThread(THREAD_SUSPEND_RESUME, false, ::GetCurrentThreadId())), |
| 72 #else |
| 69 : throttled_thread_handle_(base::PlatformThread::CurrentHandle()), | 73 : throttled_thread_handle_(base::PlatformThread::CurrentHandle()), |
| 74 #endif |
| 70 throttling_rate_percent_(static_cast<Atomic32>(rate * 100)) { | 75 throttling_rate_percent_(static_cast<Atomic32>(rate * 100)) { |
| 71 CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 1) == 0); | 76 CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 1) == 0); |
| 72 Start(); | 77 Start(); |
| 73 } | 78 } |
| 74 | 79 |
| 75 CPUThrottlingThread::~CPUThrottlingThread() { | 80 CPUThrottlingThread::~CPUThrottlingThread() { |
| 76 Stop(); | 81 Stop(); |
| 77 CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 0) == 1); | 82 CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 0) == 1); |
| 78 } | 83 } |
| 79 | 84 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return; | 201 return; |
| 197 } | 202 } |
| 198 if (throttling_thread_) { | 203 if (throttling_thread_) { |
| 199 throttling_thread_->SetThrottlingRate(rate); | 204 throttling_thread_->SetThrottlingRate(rate); |
| 200 } else { | 205 } else { |
| 201 throttling_thread_.reset(new CPUThrottlingThread(rate)); | 206 throttling_thread_.reset(new CPUThrottlingThread(rate)); |
| 202 } | 207 } |
| 203 } | 208 } |
| 204 | 209 |
| 205 } // namespace content | 210 } // namespace content |
| OLD | NEW |