diff options
Diffstat (limited to 'uisimulator/win32')
-rw-r--r-- | uisimulator/win32/kernel.c | 12 | ||||
-rw-r--r-- | uisimulator/win32/thread-win32.c | 25 | ||||
-rw-r--r-- | uisimulator/win32/thread-win32.h | 1 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.c | 10 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.h | 1 |
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 | ||
37 | void sim_sleep(int ticks) | ||
38 | { | ||
39 | Sleep (1000 / HZ * ticks); | ||
40 | } | ||
41 | |||
42 | |||
43 | void yield (void) | ||
44 | { | ||
45 | Sleep (1); /* prevent busy loop */ | ||
46 | PostThreadMessage (GetWindowThreadProcessId (hGUIWnd,NULL), TM_YIELD, 0, 0); | ||
47 | } | ||
48 | |||
49 | void queue_init(struct event_queue *q) | 37 | void 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 | ||
23 | HANDLE lpThreads[256]; | 25 | HANDLE lpThreads[256]; |
24 | int nThreads = 0, | 26 | int nThreads = 0, |
25 | nPos = 0; | 27 | nPos = 0; |
26 | long current_tick = 0; | 28 | long current_tick = 0; |
29 | CRITICAL_SECTION CriticalSection; | ||
27 | 30 | ||
28 | 31 | ||
32 | void 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 | |||
43 | void sim_sleep(int ticks) | ||
44 | { | ||
45 | LeaveCriticalSection(&CriticalSection); | ||
46 | Sleep((1000/HZ) * ticks); | ||
47 | EnterCriticalSection(&CriticalSection); | ||
48 | } | ||
49 | |||
29 | DWORD WINAPI runthread (LPVOID lpParameter) | 50 | DWORD 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 | ||
55 | void init_threads(void) | 78 | void 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 @@ | |||
20 | extern HANDLE lpThreads[256]; | 20 | extern HANDLE lpThreads[256]; |
21 | extern int nPos, | 21 | extern int nPos, |
22 | nThreads; | 22 | nThreads; |
23 | 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 () | |||
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 | ||
113 | extern HWND hGUIWnd; // the GUI window handle | 112 | extern HWND hGUIWnd; // the GUI window handle |