summaryrefslogtreecommitdiff
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
parentd83b659fa7206b150779274635a013def1ed850e (diff)
downloadrockbox-d315dfb5b1a0852d8665ef88042a9272d0b14ac5.tar.gz
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
-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)
34 return (_lv = level); 34 return (_lv = level);
35} 35}
36 36
37void sim_sleep(int ticks)
38{
39 Sleep (1000 / HZ * ticks);
40}
41
42
43void yield (void)
44{
45 Sleep (1); /* prevent busy loop */
46 PostThreadMessage (GetWindowThreadProcessId (hGUIWnd,NULL), TM_YIELD, 0, 0);
47}
48
49void queue_init(struct event_queue *q) 37void queue_init(struct event_queue *q)
50{ 38{
51 q->read = 0; 39 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 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#define WINDOWS_LEAN_AND_MEAN
20#include <windows.h> 21#include <windows.h>
21#include "thread-win32.h" 22#include "thread-win32.h"
23#include "kernel.h"
22 24
23HANDLE lpThreads[256]; 25HANDLE lpThreads[256];
24int nThreads = 0, 26int nThreads = 0,
25 nPos = 0; 27 nPos = 0;
26long current_tick = 0; 28long current_tick = 0;
29CRITICAL_SECTION CriticalSection;
27 30
28 31
32void yield(void)
33{
34 LeaveCriticalSection(&CriticalSection);
35 /* Don't need a sleep here, and it can be bad, e.g., for audio playback.
36 * Increases CPU usage a lot though. Only sleep if CPU isn't boosted
37 * could be a solution.
38 */
39 /* Sleep(1); */
40 EnterCriticalSection(&CriticalSection);
41}
42
43void sim_sleep(int ticks)
44{
45 LeaveCriticalSection(&CriticalSection);
46 Sleep((1000/HZ) * ticks);
47 EnterCriticalSection(&CriticalSection);
48}
49
29DWORD WINAPI runthread (LPVOID lpParameter) 50DWORD WINAPI runthread (LPVOID lpParameter)
30{ 51{
52 EnterCriticalSection(&CriticalSection);
31 ((void(*)())lpParameter) (); 53 ((void(*)())lpParameter) ();
54 LeaveCriticalSection(&CriticalSection);
32 return 0; 55 return 0;
33} 56}
34 57
@@ -54,4 +77,6 @@ int create_thread(void (*fp)(void), void* sp, int stk_size)
54 77
55void init_threads(void) 78void init_threads(void)
56{ 79{
80 InitializeCriticalSection(&CriticalSection);
81 EnterCriticalSection(&CriticalSection);
57} 82}
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 @@
20extern HANDLE lpThreads[256]; 20extern HANDLE lpThreads[256];
21extern int nPos, 21extern int nPos,
22 nThreads; 22 nThreads;
23extern 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 ()
262 262
263 DestroyWindow (hGUIWnd); 263 DestroyWindow (hGUIWnd);
264 CloseHandle (hGUIThread); 264 CloseHandle (hGUIThread);
265
265 for (i = 0; i < nThreads; i++) 266 for (i = 0; i < nThreads; i++)
266 { 267 {
267 ResumeThread (lpThreads[i]);
268 WaitForSingleObject (lpThreads[i], 1);
269 CloseHandle (lpThreads[i]); 268 CloseHandle (lpThreads[i]);
270 } 269 }
271 return 0; 270 return 0;
@@ -280,13 +279,6 @@ void GUIMessageLoop ()
280 { 279 {
281 TranslateMessage (&msg); 280 TranslateMessage (&msg);
282 DispatchMessage (&msg); 281 DispatchMessage (&msg);
283 if (msg.message == TM_YIELD)
284 {
285 SuspendThread (lpThreads[nPos]);
286 if (++nPos >= nThreads)
287 nPos = 0;
288 ResumeThread (lpThreads[nPos]);
289 }
290 } 282 }
291} 283}
292 284
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;
107 107
108#endif 108#endif
109 109
110#define TM_YIELD WM_USER + 101 // thread message for yield
111#define TIMER_EVENT 0x34928340 110#define TIMER_EVENT 0x34928340
112 111
113extern HWND hGUIWnd; // the GUI window handle 112extern HWND hGUIWnd; // the GUI window handle