summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2005-07-19 20:43:21 +0000
committerMagnus Holmgren <magnushol@gmail.com>2005-07-19 20:43:21 +0000
commitd315dfb5b1a0852d8665ef88042a9272d0b14ac5 (patch)
tree09b541b54e1fd5a2c74287ea58f882aa2cdf25cf /uisimulator
parentd83b659fa7206b150779274635a013def1ed850e (diff)
downloadrockbox-d315dfb5b1a0852d8665ef88042a9272d0b14ac5.tar.gz
rockbox-d315dfb5b1a0852d8665ef88042a9272d0b14ac5.tar.bz2
rockbox-d315dfb5b1a0852d8665ef88042a9272d0b14ac5.zip
Made Win32 thread management similar to the X11 one (previously yield() could make a thread stop, seemingly forever).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7202 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/win32/kernel.c12
-rw-r--r--uisimulator/win32/thread-win32.c25
-rw-r--r--uisimulator/win32/thread-win32.h1
-rw-r--r--uisimulator/win32/uisw32.c10
-rw-r--r--uisimulator/win32/uisw32.h1
5 files changed, 27 insertions, 22 deletions
diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c
index 5de436007b..8e7bb88546 100644
--- a/uisimulator/win32/kernel.c
+++ b/uisimulator/win32/kernel.c
@@ -34,18 +34,6 @@ int set_irq_level (int level)
return (_lv = level);
}
-void sim_sleep(int ticks)
-{
- Sleep (1000 / HZ * ticks);
-}
-
-
-void yield (void)
-{
- Sleep (1); /* prevent busy loop */
- PostThreadMessage (GetWindowThreadProcessId (hGUIWnd,NULL), TM_YIELD, 0, 0);
-}
-
void queue_init(struct event_queue *q)
{
q->read = 0;
diff --git a/uisimulator/win32/thread-win32.c b/uisimulator/win32/thread-win32.c
index ca973b6662..5c452d7735 100644
--- a/uisimulator/win32/thread-win32.c
+++ b/uisimulator/win32/thread-win32.c
@@ -17,18 +17,41 @@
*
****************************************************************************/
+#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include "thread-win32.h"
+#include "kernel.h"
HANDLE lpThreads[256];
int nThreads = 0,
nPos = 0;
long current_tick = 0;
+CRITICAL_SECTION CriticalSection;
+void yield(void)
+{
+ 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.
+ */
+ /* Sleep(1); */
+ EnterCriticalSection(&CriticalSection);
+}
+
+void sim_sleep(int ticks)
+{
+ LeaveCriticalSection(&CriticalSection);
+ Sleep((1000/HZ) * ticks);
+ EnterCriticalSection(&CriticalSection);
+}
+
DWORD WINAPI runthread (LPVOID lpParameter)
{
+ EnterCriticalSection(&CriticalSection);
((void(*)())lpParameter) ();
+ LeaveCriticalSection(&CriticalSection);
return 0;
}
@@ -54,4 +77,6 @@ int create_thread(void (*fp)(void), void* sp, int stk_size)
void init_threads(void)
{
+ InitializeCriticalSection(&CriticalSection);
+ EnterCriticalSection(&CriticalSection);
}
diff --git a/uisimulator/win32/thread-win32.h b/uisimulator/win32/thread-win32.h
index 2d26b8db21..467c47ee39 100644
--- a/uisimulator/win32/thread-win32.h
+++ b/uisimulator/win32/thread-win32.h
@@ -20,3 +20,4 @@
extern HANDLE lpThreads[256];
extern int nPos,
nThreads;
+extern CRITICAL_SECTION CriticalSection;
diff --git a/uisimulator/win32/uisw32.c b/uisimulator/win32/uisw32.c
index 02697be443..f492b9de36 100644
--- a/uisimulator/win32/uisw32.c
+++ b/uisimulator/win32/uisw32.c
@@ -262,10 +262,9 @@ int GUIDown ()
DestroyWindow (hGUIWnd);
CloseHandle (hGUIThread);
+
for (i = 0; i < nThreads; i++)
{
- ResumeThread (lpThreads[i]);
- WaitForSingleObject (lpThreads[i], 1);
CloseHandle (lpThreads[i]);
}
return 0;
@@ -280,13 +279,6 @@ void GUIMessageLoop ()
{
TranslateMessage (&msg);
DispatchMessage (&msg);
- if (msg.message == TM_YIELD)
- {
- SuspendThread (lpThreads[nPos]);
- if (++nPos >= nThreads)
- nPos = 0;
- ResumeThread (lpThreads[nPos]);
- }
}
}
diff --git a/uisimulator/win32/uisw32.h b/uisimulator/win32/uisw32.h
index 7d46067c60..c4ce761c80 100644
--- a/uisimulator/win32/uisw32.h
+++ b/uisimulator/win32/uisw32.h
@@ -107,7 +107,6 @@ typedef unsigned short wchar_t;
#endif
-#define TM_YIELD WM_USER + 101 // thread message for yield
#define TIMER_EVENT 0x34928340
extern HWND hGUIWnd; // the GUI window handle