mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-04-11 16:37:45 -04:00
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
This commit is contained in:
parent
1745b74576
commit
f1010005b0
5 changed files with 44 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue