From f06494477a97be9f22f5037a6f862e420cbfa26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 28 Mar 2022 17:24:35 +0200 Subject: [PATCH] uxnemu: fix the stuck threads on quit, SOMEWHAT Create threads in detached mode and check if events failed to be pushed. Stdin thread is still blocking on fread hence the "SOMEWHAT". --- src/uxnemu.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/uxnemu.c b/src/uxnemu.c index 2acaeb8..5dfb3b3 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -81,8 +81,8 @@ stdin_handler(void *p) { SDL_Event event; event.type = stdin_event; - while(fread(&event.cbutton.button, 1, 1, stdin) > 0) - SDL_PushEvent(&event); + while(fread(&event.cbutton.button, 1, 1, stdin) > 0 && SDL_PushEvent(&event) >= 0) + ; return 0; (void)p; } @@ -90,18 +90,17 @@ stdin_handler(void *p) static int redraw_handler(void *p) { - int dropped_frames = 0; + int dropped_frames = 0, stop = 0; SDL_Event event, interrupt; event.type = redraw_event; interrupt.type = interrupt_event; - for(;;) { + while(!stop) { SDL_Delay(16); if(SDL_HasEvent(redraw_event) == SDL_FALSE) { - SDL_PushEvent(&event); + stop = SDL_PushEvent(&event) < 0; dropped_frames = 0; - } - else if(++dropped_frames == TIMEOUT_FRAMES) { - SDL_PushEvent(&interrupt); + } else if(++dropped_frames == TIMEOUT_FRAMES) { + stop = SDL_PushEvent(&interrupt) < 0; } } return 0; @@ -178,8 +177,8 @@ init(void) audio0_event = SDL_RegisterEvents(POLYPHONY); redraw_event = SDL_RegisterEvents(1); interrupt_event = SDL_RegisterEvents(1); - SDL_CreateThread(stdin_handler, "stdin", NULL); - SDL_CreateThread(redraw_handler, "redraw", NULL); + SDL_DetachThread(SDL_CreateThread(stdin_handler, "stdin", NULL)); + SDL_DetachThread(SDL_CreateThread(redraw_handler, "redraw", NULL)); SDL_StartTextInput(); SDL_ShowCursor(SDL_DISABLE); SDL_EventState(SDL_DROPFILE, SDL_ENABLE);