From 03cb61f74633ebdb16e45a3f60155f20392c5108 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 28 Mar 2019 21:23:24 +1100 Subject: [PATCH] [client] main: prevent the cursor thread starting too early fixes #136 --- VERSION | 2 +- client/src/main.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index 8e0514a9..2441f2ff 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-121-gee09594190+1 \ No newline at end of file +a12-122-g8eed25b469+1 \ No newline at end of file diff --git a/client/src/main.c b/client/src/main.c index 74813fcd..d9154a70 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -166,6 +166,11 @@ struct CBRequest void * opaque; }; +// forwards +static int cursorThread(void * unused); +static int renderThread(void * unused); +static int frameThread (void * unused); + static void updatePositionInfo() { if (state.haveSrcSize) @@ -205,11 +210,19 @@ static void updatePositionInfo() state.lgrResize = true; } -int renderThread(void * unused) +static int renderThread(void * unused) { if (!state.lgr->render_startup(state.lgrData, state.window)) return 1; + // start the cursor thread after render startup to prevent a race condition + SDL_Thread *t_cursor = NULL; + if (!(t_cursor = SDL_CreateThread(cursorThread, "cursorThread", NULL))) + { + DEBUG_ERROR("cursor create thread failed"); + return 1; + } + struct timespec time; clock_gettime(CLOCK_MONOTONIC, &time); @@ -256,10 +269,12 @@ int renderThread(void * unused) clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL); } + state.running = false; + SDL_WaitThread(t_cursor, NULL); return 0; } -int cursorThread(void * unused) +static int cursorThread(void * unused) { KVMFRCursor header; LG_RendererCursor cursorType = LG_CURSOR_COLOR; @@ -373,7 +388,7 @@ int cursorThread(void * unused) return 0; } -int frameThread(void * unused) +static int frameThread(void * unused) { bool error = false; KVMFRFrame header; @@ -1133,7 +1148,6 @@ int run() } SDL_Thread *t_spice = NULL; - SDL_Thread *t_main = NULL; SDL_Thread *t_frame = NULL; SDL_Thread *t_render = NULL; @@ -1214,13 +1228,6 @@ int run() break; } - - if (!(t_main = SDL_CreateThread(cursorThread, "cursorThread", NULL))) - { - DEBUG_ERROR("cursor create thread failed"); - break; - } - if (!(t_frame = SDL_CreateThread(frameThread, "frameThread", NULL))) { DEBUG_ERROR("frame create thread failed"); @@ -1266,9 +1273,6 @@ int run() if (t_frame) SDL_WaitThread(t_frame, NULL); - if (t_main) - SDL_WaitThread(t_main, NULL); - // if spice is still connected send key up events for any pressed keys if (params.useSpiceInput && spice_ready()) {