mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
perf: limit high-resolution sleep busy-waiting
This commit is contained in:
@@ -788,14 +788,10 @@ void VideoOutDriver::Impl::PresentThread(std::stop_token token) {
|
||||
while (!token.stop_requested()) {
|
||||
const auto sleep_begin = Common::Timer::QueryPerformanceCounter();
|
||||
if (total_wait > 0) {
|
||||
const auto sleep_end = sleep_begin + static_cast<uint64_t>(total_wait);
|
||||
auto now = sleep_begin;
|
||||
while (!token.stop_requested() && now < sleep_end) {
|
||||
const auto remaining_us = (sleep_end - now) * 1000000u / frequency;
|
||||
Common::Thread::SleepMicro(
|
||||
static_cast<uint32_t>(std::clamp<uint64_t>(remaining_us, 1, 1000)));
|
||||
now = Common::Timer::QueryPerformanceCounter();
|
||||
}
|
||||
const auto remaining_us =
|
||||
(static_cast<uint64_t>(total_wait) * 1000000u + frequency - 1) / frequency;
|
||||
Common::Thread::SleepMicro(static_cast<uint32_t>(
|
||||
std::clamp<uint64_t>(remaining_us, 1, std::numeric_limits<uint32_t>::max())));
|
||||
}
|
||||
if (token.stop_requested()) {
|
||||
break;
|
||||
|
||||
@@ -752,26 +752,18 @@ void WindowContext::Run() {
|
||||
#if defined(__APPLE__)
|
||||
DrainMainThreadTasks();
|
||||
#endif
|
||||
if (SDL_PollEvent(&loop.event) != 0) {
|
||||
ProcessEvent(timer.GetTimeS());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (loop.paused.load(std::memory_order_acquire)) {
|
||||
if (!timer.IsPaused()) {
|
||||
timer.Pause();
|
||||
}
|
||||
if (SDL_WaitEvent(&loop.event) == 0) {
|
||||
EXIT("%s\n", SDL_GetError());
|
||||
}
|
||||
ProcessEvent(timer.GetTimeS());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timer.IsPaused()) {
|
||||
} else if (timer.IsPaused()) {
|
||||
timer.Resume();
|
||||
}
|
||||
Common::Thread::SleepMicro(1000);
|
||||
|
||||
if (SDL_WaitEvent(&loop.event) == 0) {
|
||||
EXIT("%s\n", SDL_GetError());
|
||||
}
|
||||
ProcessEvent(timer.GetTimeS());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user