diff --git a/src/i_video.c b/src/i_video.c index 8e448bb2..9256b56f 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -714,6 +714,17 @@ static unsigned int disk_to_draw, disk_to_restore; static void CreateUpscaledTexture(boolean force); static void I_ResetTargetRefresh(void); +// +// I_CpuPause +// Avoids a performance penalty on exit from busy-wait loops. This should be +// called on every iteration of the loop and positioned near the loop exit. +// +#if SDL_VERSION_ATLEAST(2, 24, 0) + #define I_CpuPause() SDL_CPUPauseInstruction() +#else + #define I_CpuPause() +#endif + void I_FinishUpdate(void) { if (noblit) @@ -787,6 +798,8 @@ void I_FinishUpdate(void) uint64_t elapsed_time = current_time - frametime_start; uint64_t remaining_time = 0; + I_CpuPause(); + if (elapsed_time >= target_time) { frametime_start = current_time;