#include "third_party/blink/renderer/platform/scheduler/public/thread_cpu_throttler.h"
#include <atomic>
#include <memory>
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/synchronization/atomic_flag.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_POSIX)
#include <signal.h>
#define USE_SIGNALS …
#elif BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
namespace blink {
namespace scheduler {
class ThreadCPUThrottler::ThrottlingThread final
: public base::PlatformThread::Delegate { … };
#ifdef USE_SIGNALS
bool ThreadCPUThrottler::ThrottlingThread::signal_handler_installed_;
struct sigaction ThreadCPUThrottler::ThrottlingThread::old_signal_handler_;
#endif
std::atomic<int> ThreadCPUThrottler::ThrottlingThread::throttling_rate_percent_;
std::atomic<bool> ThreadCPUThrottler::ThrottlingThread::thread_exists_;
ThreadCPUThrottler::ThrottlingThread::ThrottlingThread(double rate)
#ifdef OS_WIN
: … { … }
ThreadCPUThrottler::ThrottlingThread::~ThrottlingThread() { … }
void ThreadCPUThrottler::ThrottlingThread::SetThrottlingRate(double rate) { … }
void ThreadCPUThrottler::ThrottlingThread::ThreadMain() { … }
#ifdef USE_SIGNALS
void ThreadCPUThrottler::ThrottlingThread::InstallSignalHandler() { … }
void ThreadCPUThrottler::ThrottlingThread::RestoreSignalHandler() { … }
void ThreadCPUThrottler::ThrottlingThread::HandleSignal(int signal) { … }
#endif
void ThreadCPUThrottler::ThrottlingThread::Throttle() { … }
void ThreadCPUThrottler::ThrottlingThread::Start() { … }
void ThreadCPUThrottler::ThrottlingThread::Sleep(base::TimeDelta duration) { … }
void ThreadCPUThrottler::ThrottlingThread::Stop() { … }
ThreadCPUThrottler::ThreadCPUThrottler() = default;
ThreadCPUThrottler::~ThreadCPUThrottler() = default;
void ThreadCPUThrottler::SetThrottlingRate(double rate) { … }
ThreadCPUThrottler* ThreadCPUThrottler::GetInstance() { … }
}
}