diff options
| author | Magnus Holmgren <magnushol@gmail.com> | 2005-07-20 16:52:52 +0000 |
|---|---|---|
| committer | Magnus Holmgren <magnushol@gmail.com> | 2005-07-20 16:52:52 +0000 |
| commit | 568430421bbfbc9ae1bc409f2d26707929ec4c35 (patch) | |
| tree | 8f55efdd5705ec343e58fca540d9f005d21b9bd3 | |
| parent | bd1131e7486a3c0b5b88d5e54fdb1c1644b13b86 (diff) | |
| download | rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.zip rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.tar.gz rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.tar.bz2 rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.tar.xz | |
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
| -rw-r--r-- | uisimulator/win32/thread-win32.c | 20 |
1 files 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 <windows.h> +#include <time.h> #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); } |