summaryrefslogtreecommitdiff
path: root/uisimulator/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl')
-rw-r--r--uisimulator/sdl/system-sdl.h13
-rw-r--r--uisimulator/sdl/thread-sdl.c16
2 files changed, 21 insertions, 8 deletions
diff --git a/uisimulator/sdl/system-sdl.h b/uisimulator/sdl/system-sdl.h
index c5e7d40560..08f702d01e 100644
--- a/uisimulator/sdl/system-sdl.h
+++ b/uisimulator/sdl/system-sdl.h
@@ -24,6 +24,19 @@
24#define HIGHEST_IRQ_LEVEL 1 24#define HIGHEST_IRQ_LEVEL 1
25 25
26int set_irq_level(int level); 26int set_irq_level(int level);
27
28#define disable_irq() \
29 ((void)set_irq_level(HIGHEST_IRQ_LEVEL))
30
31#define enable_irq() \
32 ((void)set_irq_level(0))
33
34#define disable_irq_save() \
35 set_irq_level(HIGHEST_IRQ_LEVEL)
36
37#define restore_irq(level) \
38 ((void)set_irq_level(level))
39
27void sim_enter_irq_handler(void); 40void sim_enter_irq_handler(void);
28void sim_exit_irq_handler(void); 41void sim_exit_irq_handler(void);
29bool sim_kernel_init(void); 42bool sim_kernel_init(void);
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c
index 78a66f72a7..5aae9a4bf8 100644
--- a/uisimulator/sdl/thread-sdl.c
+++ b/uisimulator/sdl/thread-sdl.c
@@ -246,7 +246,7 @@ void switch_thread(void)
246{ 246{
247 struct thread_entry *current = cores[CURRENT_CORE].running; 247 struct thread_entry *current = cores[CURRENT_CORE].running;
248 248
249 set_irq_level(0); 249 enable_irq();
250 250
251 switch (current->state) 251 switch (current->state)
252 { 252 {
@@ -266,9 +266,9 @@ void switch_thread(void)
266 SDL_SemWait(current->context.s); 266 SDL_SemWait(current->context.s);
267 SDL_LockMutex(m); 267 SDL_LockMutex(m);
268 268
269 oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); 269 oldlevel = disable_irq_save();
270 current->state = STATE_RUNNING; 270 current->state = STATE_RUNNING;
271 set_irq_level(oldlevel); 271 restore_irq(oldlevel);
272 break; 272 break;
273 } /* STATE_BLOCKED: */ 273 } /* STATE_BLOCKED: */
274 274
@@ -280,7 +280,7 @@ void switch_thread(void)
280 result = SDL_SemWaitTimeout(current->context.s, current->tmo_tick); 280 result = SDL_SemWaitTimeout(current->context.s, current->tmo_tick);
281 SDL_LockMutex(m); 281 SDL_LockMutex(m);
282 282
283 oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); 283 oldlevel = disable_irq_save();
284 284
285 if (current->state == STATE_BLOCKED_W_TMO) 285 if (current->state == STATE_BLOCKED_W_TMO)
286 { 286 {
@@ -303,7 +303,7 @@ void switch_thread(void)
303 SDL_SemTryWait(current->context.s); 303 SDL_SemTryWait(current->context.s);
304 } 304 }
305 305
306 set_irq_level(oldlevel); 306 restore_irq(oldlevel);
307 break; 307 break;
308 } /* STATE_BLOCKED_W_TMO: */ 308 } /* STATE_BLOCKED_W_TMO: */
309 309
@@ -505,7 +505,7 @@ void remove_thread(struct thread_entry *thread)
505 SDL_Thread *t; 505 SDL_Thread *t;
506 SDL_sem *s; 506 SDL_sem *s;
507 507
508 int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); 508 int oldlevel = disable_irq_save();
509 509
510 if (thread == NULL) 510 if (thread == NULL)
511 { 511 {
@@ -547,12 +547,12 @@ void remove_thread(struct thread_entry *thread)
547 { 547 {
548 /* Do a graceful exit - perform the longjmp back into the thread 548 /* Do a graceful exit - perform the longjmp back into the thread
549 function to return */ 549 function to return */
550 set_irq_level(oldlevel); 550 restore_irq(oldlevel);
551 longjmp(thread_jmpbufs[current - threads], 1); 551 longjmp(thread_jmpbufs[current - threads], 1);
552 } 552 }
553 553
554 SDL_KillThread(t); 554 SDL_KillThread(t);
555 set_irq_level(oldlevel); 555 restore_irq(oldlevel);
556} 556}
557 557
558void thread_exit(void) 558void thread_exit(void)