summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2005-07-20 16:52:52 +0000
committerMagnus Holmgren <magnushol@gmail.com>2005-07-20 16:52:52 +0000
commit568430421bbfbc9ae1bc409f2d26707929ec4c35 (patch)
tree8f55efdd5705ec343e58fca540d9f005d21b9bd3 /uisimulator
parentbd1131e7486a3c0b5b88d5e54fdb1c1644b13b86 (diff)
downloadrockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.tar.gz
rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.tar.bz2
rockbox-568430421bbfbc9ae1bc409f2d26707929ec4c35.zip
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
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/win32/thread-win32.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/uisimulator/win32/thread-win32.c b/uisimulator/win32/thread-win32.c
index 5c452d7735..bfad7cc1e8 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);
}