diff options
author | Christian Soffke <christian.soffke@gmail.com> | 2023-08-14 21:15:50 +0200 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-12-01 20:18:11 -0500 |
commit | f1010005b051cdaeaeee0b23ad85b14e9c05be12 (patch) | |
tree | 45a097dc66a8af8e45915faf92bb021c370df1ed | |
parent | 1745b745765605c2f3a353a413f5cc66c73bc3cb (diff) | |
download | rockbox-f1010005b0.tar.gz rockbox-f1010005b0.zip |
Fix simulator crashing on MacOS
Event handling must happen on the main
thread for MacOS.
Not sure if button_queue_wait is the
best place for doing the SDL event
polling, but seems to work ok.
Change-Id: If928282df84bdd74e24a48afd7dbc4c4bfcc49e2
-rw-r--r-- | apps/tagcache.c | 2 | ||||
-rw-r--r-- | firmware/drivers/button_queue.c | 25 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.c | 9 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.h | 4 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.c | 4 |
5 files changed, 44 insertions, 0 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 7d8d2aec22..314e79acf7 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -5176,11 +5176,13 @@ static void tagcache_thread(void) * the changes first in foreground. */ if (db_file_exists(TAGCACHE_FILE_TEMP)) { +#if !(defined(__APPLE__) && (CONFIG_PLATFORM & PLATFORM_SDL)) static const char *lines[] = {ID2P(LANG_TAGCACHE_BUSY), ID2P(LANG_TAGCACHE_UPDATE)}; static const struct text_message message = {lines, 2}; if (gui_syncyesno_run_w_tmo(HZ * 5, YESNO_YES, &message, NULL, NULL) == YESNO_YES) +#endif { allocate_tempbuf(); commit(); diff --git a/firmware/drivers/button_queue.c b/firmware/drivers/button_queue.c index 6b4d0509d1..1679fc224e 100644 --- a/firmware/drivers/button_queue.c +++ b/firmware/drivers/button_queue.c @@ -22,6 +22,9 @@ #include "system.h" #include "kernel.h" #include "button.h" +#ifdef HAVE_SDL +#include "button-sdl.h" +#endif static struct event_queue button_queue SHAREDBSS_ATTR; static intptr_t button_data; /* data value from last message dequeued */ @@ -92,7 +95,29 @@ static void button_queue_wait(struct queue_event *evp, int timeout) #else /* ndef HAVE_ADJUSTABLE_CPU_FREQ */ static inline void button_queue_wait(struct queue_event *evp, int timeout) { +#if defined(__APPLE__) && (CONFIG_PLATFORM & PLATFORM_SDL) + unsigned long initial_tick = current_tick; + unsigned long curr_tick, remaining; + while(true) + { + handle_sdl_events(); + queue_wait_w_tmo(&button_queue, evp, TIMEOUT_NOBLOCK); + if (evp->id != SYS_TIMEOUT || timeout == TIMEOUT_NOBLOCK) + return; + else if (timeout == TIMEOUT_BLOCK) + sleep(HZ/60); + else + { + curr_tick = current_tick; + if (!TIME_AFTER(initial_tick + timeout, curr_tick)) + return; + remaining = ((initial_tick + timeout) - curr_tick); + sleep(remaining < HZ/60 ? remaining : HZ/60); + } + } +#else queue_wait_w_tmo(&button_queue, evp, timeout); +#endif } #endif /* HAVE_ADJUSTABLE_CPU_FREQ */ diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c index 49e4b15df4..621b63f930 100644 --- a/firmware/target/hosted/sdl/button-sdl.c +++ b/firmware/target/hosted/sdl/button-sdl.c @@ -307,6 +307,15 @@ static bool event_handler(SDL_Event *event) return false; } +#ifdef __APPLE__ +void handle_sdl_events(void) +{ + SDL_Event event; + while(SDL_PollEvent(&event)) + event_handler(&event); +} +#endif + void gui_message_loop(void) { SDL_Event event; diff --git a/firmware/target/hosted/sdl/button-sdl.h b/firmware/target/hosted/sdl/button-sdl.h index 6b7f632eaf..dd6322c884 100644 --- a/firmware/target/hosted/sdl/button-sdl.h +++ b/firmware/target/hosted/sdl/button-sdl.h @@ -28,6 +28,10 @@ extern int sdl_app_has_input_focus; +#ifdef __APPLE__ +void handle_sdl_events(void); +#endif + bool button_hold(void); #undef button_init_device void button_init_device(void); diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index 56cff3f1be..22186a5e36 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -138,6 +138,7 @@ static void sdl_window_setup(void) } } +#ifndef __APPLE__ /* MacOS requires events to be handled on main thread */ /* * This thread will read the buttons in an interrupt like fashion, and * also initializes SDL_INIT_VIDEO and the surfaces @@ -205,6 +206,7 @@ static int sdl_event_thread(void * param) #endif return 0; } +#endif static bool quitting; @@ -270,11 +272,13 @@ void system_init(void) sdl_window_setup(); #endif +#ifndef __APPLE__ /* MacOS requires events to be handled on main thread */ s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ evt_thread = SDL_CreateThread(sdl_event_thread, NULL, s); SDL_SemWait(s); /* cleanup */ SDL_DestroySemaphore(s); +#endif } |