System: Use hybrid sleep on Android

This commit is contained in:
Connor McLaughlin 2021-01-26 02:22:59 +10:00
parent 52f5ca7e28
commit e79dff1731
1 changed files with 3 additions and 34 deletions

View File

@ -39,12 +39,6 @@
#include <limits> #include <limits>
Log_SetChannel(System); Log_SetChannel(System);
#ifdef WIN32
#include "common/windows_headers.h"
#else
#include <time.h>
#endif
SystemBootParameters::SystemBootParameters() = default; SystemBootParameters::SystemBootParameters() = default;
SystemBootParameters::SystemBootParameters(SystemBootParameters&& other) = default; SystemBootParameters::SystemBootParameters(SystemBootParameters&& other) = default;
@ -1391,35 +1385,10 @@ void Throttle()
} }
else if (sleep_time >= MINIMUM_SLEEP_TIME) else if (sleep_time >= MINIMUM_SLEEP_TIME)
{ {
#ifdef WIN32 #ifdef __ANDROID__
static HANDLE throttle_timer; Common::Timer::HybridSleep(sleep_time);
static bool throttle_timer_created = false;
if (!throttle_timer_created)
{
throttle_timer_created = true;
throttle_timer = CreateWaitableTimer(nullptr, TRUE, nullptr);
if (throttle_timer)
std::atexit([]() { CloseHandle(throttle_timer); });
else
Log_ErrorPrintf("CreateWaitableTimer() failed, falling back to Sleep()");
}
if (throttle_timer)
{
LARGE_INTEGER due_time;
due_time.QuadPart = -static_cast<s64>(static_cast<u64>(sleep_time) / 100u);
if (SetWaitableTimer(throttle_timer, &due_time, 0, nullptr, nullptr, FALSE))
WaitForSingleObject(throttle_timer, INFINITE);
else
Log_ErrorPrintf("SetWaitableTimer() failed: %08X", GetLastError());
}
else
{
Sleep(static_cast<u32>(sleep_time / 1000000));
}
#else #else
const struct timespec ts = {0, static_cast<long>(sleep_time)}; Common::Timer::NanoSleep(sleep_time);
nanosleep(&ts, nullptr);
#endif #endif
} }