diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/common/io.c | 3 | ||||
-rw-r--r-- | uisimulator/sdl/button.c | 25 | ||||
-rw-r--r-- | uisimulator/sdl/kernel.c | 20 | ||||
-rw-r--r-- | uisimulator/sdl/thread-sdl.c | 25 | ||||
-rw-r--r-- | uisimulator/sdl/thread-sdl.h | 2 | ||||
-rw-r--r-- | uisimulator/sdl/uisdl.c | 6 |
6 files changed, 66 insertions, 15 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 127a1c36f1..463bbc68d9 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -261,7 +261,8 @@ void sim_io_init(void) | |||
261 | } | 261 | } |
262 | 262 | ||
263 | /* Wait for IO thread to lock mutex */ | 263 | /* Wait for IO thread to lock mutex */ |
264 | while (!io.ready); | 264 | while (!io.ready) |
265 | SDL_Delay(0); | ||
265 | 266 | ||
266 | /* Wait for it to unlock */ | 267 | /* Wait for it to unlock */ |
267 | SDL_LockMutex(io.m); | 268 | SDL_LockMutex(io.m); |
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c index 1bb9311890..4869dd06b1 100644 --- a/uisimulator/sdl/button.c +++ b/uisimulator/sdl/button.c | |||
@@ -30,6 +30,11 @@ | |||
30 | 30 | ||
31 | static intptr_t button_data; /* data value from last message dequeued */ | 31 | static intptr_t button_data; /* data value from last message dequeued */ |
32 | 32 | ||
33 | /* Special thread-synced queue_post for button driver or any other preemptive sim thread */ | ||
34 | extern void queue_syncpost(struct event_queue *q, long id, intptr_t data); | ||
35 | /* Special thread-synced queue_broadcast for button driver or any other preemptive sim thread */ | ||
36 | extern int queue_syncbroadcast(long id, intptr_t data); | ||
37 | |||
33 | /* how long until repeat kicks in */ | 38 | /* how long until repeat kicks in */ |
34 | #define REPEAT_START 6 | 39 | #define REPEAT_START 6 |
35 | 40 | ||
@@ -110,9 +115,9 @@ void button_event(int key, bool pressed) | |||
110 | { | 115 | { |
111 | usb_connected = !usb_connected; | 116 | usb_connected = !usb_connected; |
112 | if (usb_connected) | 117 | if (usb_connected) |
113 | queue_post(&button_queue, SYS_USB_CONNECTED, 0); | 118 | queue_syncpost(&button_queue, SYS_USB_CONNECTED, 0); |
114 | else | 119 | else |
115 | queue_post(&button_queue, SYS_USB_DISCONNECTED, 0); | 120 | queue_syncpost(&button_queue, SYS_USB_DISCONNECTED, 0); |
116 | } | 121 | } |
117 | return; | 122 | return; |
118 | 123 | ||
@@ -590,7 +595,7 @@ void button_event(int key, bool pressed) | |||
590 | case SDLK_F5: | 595 | case SDLK_F5: |
591 | if(pressed) | 596 | if(pressed) |
592 | { | 597 | { |
593 | screen_dump(); | 598 | queue_syncbroadcast(SYS_SCREENDUMP, 0); |
594 | return; | 599 | return; |
595 | } | 600 | } |
596 | break; | 601 | break; |
@@ -611,17 +616,17 @@ void button_event(int key, bool pressed) | |||
611 | #ifdef HAVE_REMOTE_LCD | 616 | #ifdef HAVE_REMOTE_LCD |
612 | if(diff & BUTTON_REMOTE) | 617 | if(diff & BUTTON_REMOTE) |
613 | if(!skip_remote_release) | 618 | if(!skip_remote_release) |
614 | queue_post(&button_queue, BUTTON_REL | diff, 0); | 619 | queue_syncpost(&button_queue, BUTTON_REL | diff, 0); |
615 | else | 620 | else |
616 | skip_remote_release = false; | 621 | skip_remote_release = false; |
617 | else | 622 | else |
618 | #endif | 623 | #endif |
619 | if(!skip_release) | 624 | if(!skip_release) |
620 | queue_post(&button_queue, BUTTON_REL | diff, 0); | 625 | queue_syncpost(&button_queue, BUTTON_REL | diff, 0); |
621 | else | 626 | else |
622 | skip_release = false; | 627 | skip_release = false; |
623 | #else | 628 | #else |
624 | queue_post(&button_queue, BUTTON_REL | diff, 0); | 629 | queue_syncpost(&button_queue, BUTTON_REL | diff, 0); |
625 | #endif | 630 | #endif |
626 | } | 631 | } |
627 | 632 | ||
@@ -673,7 +678,7 @@ void button_event(int key, bool pressed) | |||
673 | { | 678 | { |
674 | if (queue_empty(&button_queue)) | 679 | if (queue_empty(&button_queue)) |
675 | { | 680 | { |
676 | queue_post(&button_queue, BUTTON_REPEAT | btn, 0); | 681 | queue_syncpost(&button_queue, BUTTON_REPEAT | btn, 0); |
677 | #ifdef HAVE_BACKLIGHT | 682 | #ifdef HAVE_BACKLIGHT |
678 | #ifdef HAVE_REMOTE_LCD | 683 | #ifdef HAVE_REMOTE_LCD |
679 | if(btn & BUTTON_REMOTE) | 684 | if(btn & BUTTON_REMOTE) |
@@ -695,18 +700,18 @@ void button_event(int key, bool pressed) | |||
695 | #ifdef HAVE_REMOTE_LCD | 700 | #ifdef HAVE_REMOTE_LCD |
696 | if (btn & BUTTON_REMOTE) { | 701 | if (btn & BUTTON_REMOTE) { |
697 | if (!remote_filter_first_keypress || is_remote_backlight_on()) | 702 | if (!remote_filter_first_keypress || is_remote_backlight_on()) |
698 | queue_post(&button_queue, btn, 0); | 703 | queue_syncpost(&button_queue, btn, 0); |
699 | else | 704 | else |
700 | skip_remote_release = true; | 705 | skip_remote_release = true; |
701 | } | 706 | } |
702 | else | 707 | else |
703 | #endif | 708 | #endif |
704 | if (!filter_first_keypress || is_backlight_on()) | 709 | if (!filter_first_keypress || is_backlight_on()) |
705 | queue_post(&button_queue, btn, 0); | 710 | queue_syncpost(&button_queue, btn, 0); |
706 | else | 711 | else |
707 | skip_release = true; | 712 | skip_release = true; |
708 | #else /* no backlight, nothing to skip */ | 713 | #else /* no backlight, nothing to skip */ |
709 | queue_post(&button_queue, btn, 0); | 714 | queue_syncpost(&button_queue, btn, 0); |
710 | #endif | 715 | #endif |
711 | post = false; | 716 | post = false; |
712 | } | 717 | } |
diff --git a/uisimulator/sdl/kernel.c b/uisimulator/sdl/kernel.c index c82c6632cf..ff6c94933b 100644 --- a/uisimulator/sdl/kernel.c +++ b/uisimulator/sdl/kernel.c | |||
@@ -225,6 +225,15 @@ void queue_post(struct event_queue *q, long id, intptr_t data) | |||
225 | wakeup_thread(&q->thread); | 225 | wakeup_thread(&q->thread); |
226 | } | 226 | } |
227 | 227 | ||
228 | /* Special thread-synced queue_post for button driver or any other preemptive sim thread */ | ||
229 | void queue_syncpost(struct event_queue *q, long id, intptr_t data) | ||
230 | { | ||
231 | thread_sdl_lock(); | ||
232 | /* No rockbox threads can be running here */ | ||
233 | queue_post(q, id, data); | ||
234 | thread_sdl_unlock(); | ||
235 | } | ||
236 | |||
228 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME | 237 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME |
229 | intptr_t queue_send(struct event_queue *q, long id, intptr_t data) | 238 | intptr_t queue_send(struct event_queue *q, long id, intptr_t data) |
230 | { | 239 | { |
@@ -332,6 +341,17 @@ int queue_broadcast(long id, intptr_t data) | |||
332 | return num_queues; | 341 | return num_queues; |
333 | } | 342 | } |
334 | 343 | ||
344 | /* Special thread-synced queue_broadcast for button driver or any other preemptive sim thread */ | ||
345 | int queue_syncbroadcast(long id, intptr_t data) | ||
346 | { | ||
347 | int i; | ||
348 | thread_sdl_lock(); | ||
349 | /* No rockbox threads can be running here */ | ||
350 | i = queue_broadcast(id, data); | ||
351 | thread_sdl_unlock(); | ||
352 | return i; | ||
353 | } | ||
354 | |||
335 | void yield(void) | 355 | void yield(void) |
336 | { | 356 | { |
337 | switch_thread(true, NULL); | 357 | switch_thread(true, NULL); |
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c index aac8e2fbb9..8769b5d84f 100644 --- a/uisimulator/sdl/thread-sdl.c +++ b/uisimulator/sdl/thread-sdl.c | |||
@@ -48,6 +48,8 @@ static SDL_mutex *m; | |||
48 | static SDL_sem *s; | 48 | static SDL_sem *s; |
49 | static struct thread_entry *running; | 49 | static struct thread_entry *running; |
50 | 50 | ||
51 | extern long start_tick; | ||
52 | |||
51 | void kill_sim_threads(void) | 53 | void kill_sim_threads(void) |
52 | { | 54 | { |
53 | int i; | 55 | int i; |
@@ -62,6 +64,7 @@ void kill_sim_threads(void) | |||
62 | SDL_SemPost(s); | 64 | SDL_SemPost(s); |
63 | else | 65 | else |
64 | SDL_CondSignal(thread->context.c); | 66 | SDL_CondSignal(thread->context.c); |
67 | SDL_Delay(10); | ||
65 | SDL_KillThread(thread->context.t); | 68 | SDL_KillThread(thread->context.t); |
66 | SDL_DestroyCond(thread->context.c); | 69 | SDL_DestroyCond(thread->context.c); |
67 | } | 70 | } |
@@ -129,6 +132,16 @@ struct thread_entry *thread_get_current(void) | |||
129 | return running; | 132 | return running; |
130 | } | 133 | } |
131 | 134 | ||
135 | void thread_sdl_lock(void) | ||
136 | { | ||
137 | SDL_LockMutex(m); | ||
138 | } | ||
139 | |||
140 | void thread_sdl_unlock(void) | ||
141 | { | ||
142 | SDL_UnlockMutex(m); | ||
143 | } | ||
144 | |||
132 | void switch_thread(bool save_context, struct thread_entry **blocked_list) | 145 | void switch_thread(bool save_context, struct thread_entry **blocked_list) |
133 | { | 146 | { |
134 | struct thread_entry *current = running; | 147 | struct thread_entry *current = running; |
@@ -137,6 +150,8 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list) | |||
137 | 150 | ||
138 | SDL_SemWait(s); | 151 | SDL_SemWait(s); |
139 | 152 | ||
153 | SDL_Delay(0); | ||
154 | |||
140 | SDL_LockMutex(m); | 155 | SDL_LockMutex(m); |
141 | running = current; | 156 | running = current; |
142 | 157 | ||
@@ -148,11 +163,19 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list) | |||
148 | void sleep_thread(int ticks) | 163 | void sleep_thread(int ticks) |
149 | { | 164 | { |
150 | struct thread_entry *current; | 165 | struct thread_entry *current; |
166 | int rem; | ||
151 | 167 | ||
152 | current = running; | 168 | current = running; |
153 | current->statearg = STATE_SLEEPING; | 169 | current->statearg = STATE_SLEEPING; |
154 | 170 | ||
155 | SDL_CondWaitTimeout(current->context.c, m, (1000/HZ) * ticks + (500/HZ)); | 171 | rem = (SDL_GetTicks() - start_tick) % (1000/HZ); |
172 | if (rem < 0) | ||
173 | rem = 0; | ||
174 | |||
175 | SDL_UnlockMutex(m); | ||
176 | SDL_Delay((1000/HZ) * ticks + ((1000/HZ)-1) - rem); | ||
177 | SDL_LockMutex(m); | ||
178 | |||
156 | running = current; | 179 | running = current; |
157 | 180 | ||
158 | current->statearg = STATE_RUNNING; | 181 | current->statearg = STATE_RUNNING; |
diff --git a/uisimulator/sdl/thread-sdl.h b/uisimulator/sdl/thread-sdl.h index 20641fb673..90dffd6806 100644 --- a/uisimulator/sdl/thread-sdl.h +++ b/uisimulator/sdl/thread-sdl.h | |||
@@ -24,6 +24,8 @@ | |||
24 | 24 | ||
25 | extern SDL_Thread *gui_thread; /* The "main" thread */ | 25 | extern SDL_Thread *gui_thread; /* The "main" thread */ |
26 | void kill_sim_threads(); /* Kill all the rockbox sim threads */ | 26 | void kill_sim_threads(); /* Kill all the rockbox sim threads */ |
27 | void thread_sdl_lock(void); /* Sync with SDL threads */ | ||
28 | void thread_sdl_unlock(void); /* Sync with SDL threads */ | ||
27 | 29 | ||
28 | #endif /* #ifndef __THREADSDL_H__ */ | 30 | #endif /* #ifndef __THREADSDL_H__ */ |
29 | 31 | ||
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 37a0e6fe7a..fdd40beb23 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c | |||
@@ -41,8 +41,8 @@ | |||
41 | extern void app_main (void *); /* mod entry point */ | 41 | extern void app_main (void *); /* mod entry point */ |
42 | extern void new_key(int key); | 42 | extern void new_key(int key); |
43 | extern void sim_tick_tasks(void); | 43 | extern void sim_tick_tasks(void); |
44 | extern void sim_io_init(void); | 44 | extern void sim_io_init(void); |
45 | extern void sim_io_shutdown(void); | 45 | extern void sim_io_shutdown(void); |
46 | 46 | ||
47 | void button_event(int key, bool pressed); | 47 | void button_event(int key, bool pressed); |
48 | 48 | ||
@@ -69,7 +69,7 @@ Uint32 tick_timer(Uint32 interval, void *param) | |||
69 | (void) interval; | 69 | (void) interval; |
70 | (void) param; | 70 | (void) param; |
71 | 71 | ||
72 | new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000; | 72 | new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ); |
73 | 73 | ||
74 | if (new_tick != current_tick) { | 74 | if (new_tick != current_tick) { |
75 | long i; | 75 | long i; |