summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-09-09 01:59:07 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-09-09 01:59:07 +0000
commit0107dfc8276d73744bb097d643809205ef21d97b (patch)
tree17d434f51652d949d8167abaf85fe0eacd33612a
parent424750ea95409c6e78188aa47fe7a0f47d1127cb (diff)
downloadrockbox-0107dfc8276d73744bb097d643809205ef21d97b.tar.gz
rockbox-0107dfc8276d73744bb097d643809205ef21d97b.zip
UISIMULATOR: Give the host OS some needed context switching hints (which _is_ supposed to work on Linux - but I can't tell on VMWare - and does on Windows). I guess I'll know for sure soon. Give sleep() even more genuine behavior. Add some button driver sync with the rockbox threads that should have been there for some time - this is basically interrupt-like processing as any thread not in the kernel pool should be considered. Make the screendump work again by posting the request. Perhaps help out shutting down for some users but not in the way I'd prefer - to think about.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14646 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/backlight.c7
-rw-r--r--firmware/export/kernel.h2
-rw-r--r--uisimulator/common/io.c3
-rw-r--r--uisimulator/sdl/button.c25
-rw-r--r--uisimulator/sdl/kernel.c20
-rw-r--r--uisimulator/sdl/thread-sdl.c25
-rw-r--r--uisimulator/sdl/thread-sdl.h2
-rw-r--r--uisimulator/sdl/uisdl.c6
8 files changed, 74 insertions, 16 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 2ba4d6ed1d..41f0f75424 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -487,7 +487,12 @@ void backlight_thread(void)
487 lcd_remote_off(); 487 lcd_remote_off();
488 break; 488 break;
489#endif /* defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR) */ 489#endif /* defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR) */
490 490#ifdef SIMULATOR
491 /* This one here too for lack of a better place */
492 case SYS_SCREENDUMP:
493 screen_dump();
494 break;
495#endif
491 case SYS_USB_CONNECTED: 496 case SYS_USB_CONNECTED:
492 /* Tell the USB thread that we are safe */ 497 /* Tell the USB thread that we are safe */
493 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n"); 498 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index bf5a9d10c3..9ada8eb59c 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -41,6 +41,7 @@
41#define SYS_EVENT_CLS_POWER 2 41#define SYS_EVENT_CLS_POWER 2
42#define SYS_EVENT_CLS_FILESYS 3 42#define SYS_EVENT_CLS_FILESYS 3
43#define SYS_EVENT_CLS_PLUG 4 43#define SYS_EVENT_CLS_PLUG 4
44#define SYS_EVENT_CLS_MISC 5
44/* make sure SYS_EVENT_CLS_BITS has enough range */ 45/* make sure SYS_EVENT_CLS_BITS has enough range */
45 46
46/* Bit 31->|S|c...c|i...i| */ 47/* Bit 31->|S|c...c|i...i| */
@@ -68,6 +69,7 @@
68#define SYS_PHONE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 3) 69#define SYS_PHONE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 3)
69#define SYS_REMOTE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 4) 70#define SYS_REMOTE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 4)
70#define SYS_REMOTE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 5) 71#define SYS_REMOTE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 5)
72#define SYS_SCREENDUMP MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 0)
71 73
72struct event 74struct event
73{ 75{
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
31static intptr_t button_data; /* data value from last message dequeued */ 31static 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 */
34extern 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 */
36extern 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 */
229void 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
229intptr_t queue_send(struct event_queue *q, long id, intptr_t data) 238intptr_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 */
345int 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
335void yield(void) 355void 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;
48static SDL_sem *s; 48static SDL_sem *s;
49static struct thread_entry *running; 49static struct thread_entry *running;
50 50
51extern long start_tick;
52
51void kill_sim_threads(void) 53void 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
135void thread_sdl_lock(void)
136{
137 SDL_LockMutex(m);
138}
139
140void thread_sdl_unlock(void)
141{
142 SDL_UnlockMutex(m);
143}
144
132void switch_thread(bool save_context, struct thread_entry **blocked_list) 145void 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)
148void sleep_thread(int ticks) 163void 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
25extern SDL_Thread *gui_thread; /* The "main" thread */ 25extern SDL_Thread *gui_thread; /* The "main" thread */
26void kill_sim_threads(); /* Kill all the rockbox sim threads */ 26void kill_sim_threads(); /* Kill all the rockbox sim threads */
27void thread_sdl_lock(void); /* Sync with SDL threads */
28void 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 @@
41extern void app_main (void *); /* mod entry point */ 41extern void app_main (void *); /* mod entry point */
42extern void new_key(int key); 42extern void new_key(int key);
43extern void sim_tick_tasks(void); 43extern void sim_tick_tasks(void);
44extern void sim_io_init(void); 44extern void sim_io_init(void);
45extern void sim_io_shutdown(void); 45extern void sim_io_shutdown(void);
46 46
47void button_event(int key, bool pressed); 47void 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;