From 568430421bbfbc9ae1bc409f2d26707929ec4c35 Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Wed, 20 Jul 2005 16:52:52 +0000 Subject: Don't hog the CPU, but keep sound playback working. (This might need some tweaking...) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7206 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/win32/thread-win32.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/uisimulator/win32/thread-win32.c b/uisimulator/win32/thread-win32.c index 5c452d7..bfad7cc 100644 --- a/uisimulator/win32/thread-win32.c +++ b/uisimulator/win32/thread-win32.c @@ -19,8 +19,10 @@ #define WINDOWS_LEAN_AND_MEAN #include +#include #include "thread-win32.h" #include "kernel.h" +#include "debug.h" HANDLE lpThreads[256]; int nThreads = 0, @@ -31,12 +33,22 @@ CRITICAL_SECTION CriticalSection; void yield(void) { + static clock_t last = 0; + clock_t now; + LeaveCriticalSection(&CriticalSection); - /* Don't need a sleep here, and it can be bad, e.g., for audio playback. - * Increases CPU usage a lot though. Only sleep if CPU isn't boosted - * could be a solution. + /* Don't call Sleep() too often (as the smallest sleep really is a bit + * longer). This keeps CPU usage low, yet allows sound playback to work + * well (at least on one particular computer). */ - /* Sleep(1); */ + now = clock(); + + if (now - last > CLOCKS_PER_SEC / 200) + { + last = now; + Sleep(1); + } + EnterCriticalSection(&CriticalSection); } -- cgit v1.1