From e3cd78b53b9a39913d847c4ef1779f14a391177f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 13 Oct 2012 09:27:07 +0100 Subject: [PATCH] retrace: Sleep when polling for input. As Carl Worth identified, if the user passed the "-w" option to beable to see the last frame of the retrace, the glretrace would enter a busy-waiting loop, consuming as much CPU as possible. --- common/os_time.hpp | 24 ++++++++++++++++++------ retrace/d3dretrace_main.cpp | 1 + retrace/glretrace_main.cpp | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/os_time.hpp b/common/os_time.hpp index 75175d8..13cc733 100644 --- a/common/os_time.hpp +++ b/common/os_time.hpp @@ -32,13 +32,16 @@ #if defined(_WIN32) -#include -#elif defined(__linux__) -#include -#elif defined(__APPLE__) -#include +# include #else -#include +# if defined(__linux__) +# include +# elif defined(__APPLE__) +# include +# else +# include +# endif +# include #endif @@ -88,6 +91,15 @@ namespace os { #endif } + // Suspend execution + inline void + sleep(unsigned long usecs) { +#if defined(_WIN32) + Sleep((usecs + 999) / 1000); +#else + usleep(usecs); +#endif + } } /* namespace os */ diff --git a/retrace/d3dretrace_main.cpp b/retrace/d3dretrace_main.cpp index 40d53ea..9878fe3 100644 --- a/retrace/d3dretrace_main.cpp +++ b/retrace/d3dretrace_main.cpp @@ -87,6 +87,7 @@ retrace::flushRendering(void) { void retrace::waitForInput(void) { + /* TODO */ } void diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp index d857d03..1086be9 100755 --- a/retrace/glretrace_main.cpp +++ b/retrace/glretrace_main.cpp @@ -435,6 +435,7 @@ retrace::flushRendering(void) { void retrace::waitForInput(void) { while (glws::processEvents()) { + os::sleep(100*1000); } } -- 2.43.0