commit f06494477a97be9f22f5037a6f862e420cbfa26b
parent a325798cb33fc05d10e60d02862a42060806671a
Author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date: Mon, 28 Mar 2022 17:24:35 +0200
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".
Diffstat:
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git 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);