[client] main: prevent the cursor thread starting too early

fixes #136
This commit is contained in:
Geoffrey McRae 2019-03-28 21:23:24 +11:00
parent 8eed25b469
commit 03cb61f746
2 changed files with 19 additions and 15 deletions

View File

@ -1 +1 @@
a12-121-gee09594190+1 a12-122-g8eed25b469+1

View File

@ -166,6 +166,11 @@ struct CBRequest
void * opaque; void * opaque;
}; };
// forwards
static int cursorThread(void * unused);
static int renderThread(void * unused);
static int frameThread (void * unused);
static void updatePositionInfo() static void updatePositionInfo()
{ {
if (state.haveSrcSize) if (state.haveSrcSize)
@ -205,11 +210,19 @@ static void updatePositionInfo()
state.lgrResize = true; state.lgrResize = true;
} }
int renderThread(void * unused) static int renderThread(void * unused)
{ {
if (!state.lgr->render_startup(state.lgrData, state.window)) if (!state.lgr->render_startup(state.lgrData, state.window))
return 1; 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; struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time); clock_gettime(CLOCK_MONOTONIC, &time);
@ -256,10 +269,12 @@ int renderThread(void * unused)
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL); clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL);
} }
state.running = false;
SDL_WaitThread(t_cursor, NULL);
return 0; return 0;
} }
int cursorThread(void * unused) static int cursorThread(void * unused)
{ {
KVMFRCursor header; KVMFRCursor header;
LG_RendererCursor cursorType = LG_CURSOR_COLOR; LG_RendererCursor cursorType = LG_CURSOR_COLOR;
@ -373,7 +388,7 @@ int cursorThread(void * unused)
return 0; return 0;
} }
int frameThread(void * unused) static int frameThread(void * unused)
{ {
bool error = false; bool error = false;
KVMFRFrame header; KVMFRFrame header;
@ -1133,7 +1148,6 @@ int run()
} }
SDL_Thread *t_spice = NULL; SDL_Thread *t_spice = NULL;
SDL_Thread *t_main = NULL;
SDL_Thread *t_frame = NULL; SDL_Thread *t_frame = NULL;
SDL_Thread *t_render = NULL; SDL_Thread *t_render = NULL;
@ -1214,13 +1228,6 @@ int run()
break; break;
} }
if (!(t_main = SDL_CreateThread(cursorThread, "cursorThread", NULL)))
{
DEBUG_ERROR("cursor create thread failed");
break;
}
if (!(t_frame = SDL_CreateThread(frameThread, "frameThread", NULL))) if (!(t_frame = SDL_CreateThread(frameThread, "frameThread", NULL)))
{ {
DEBUG_ERROR("frame create thread failed"); DEBUG_ERROR("frame create thread failed");
@ -1266,9 +1273,6 @@ int run()
if (t_frame) if (t_frame)
SDL_WaitThread(t_frame, NULL); 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 spice is still connected send key up events for any pressed keys
if (params.useSpiceInput && spice_ready()) if (params.useSpiceInput && spice_ready())
{ {