From 1770defea297358ab79df4c6daa4e3b859a450f7 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 27 May 2022 09:22:10 +1000 Subject: [PATCH] [client] spice: wait for the spice connection to finish at startup A failure to connect to spice would cause LG to exit late, this adds a startup condition that prevents the LG initialization to complete until the spice connection has been established. --- client/src/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/src/main.c b/client/src/main.c index ce3b6ccf..1ea396e6 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -69,6 +69,7 @@ static int renderThread(void * unused); static LGEvent *e_startup = NULL; +static LGEvent *e_spice = NULL; static LGThread *t_spice = NULL; static LGThread *t_render = NULL; @@ -888,6 +889,7 @@ void spiceReady(void) keybind_spiceRegister(); purespice_freeServerInfo(&info); + lgSignalEvent(e_spice); } static void spice_surfaceCreate(unsigned int surfaceId, PSSurfaceFormat format, @@ -987,6 +989,7 @@ int spiceThread(void * arg) if (!purespice_connect(&config)) { DEBUG_ERROR("Failed to connect to spice server"); + lgSignalEvent(e_spice); goto end; } @@ -1024,6 +1027,7 @@ end: if (!g_state.spiceClose) g_state.state = APP_STATE_SHUTDOWN; + lgSignalEvent(e_spice); return 0; } @@ -1190,6 +1194,13 @@ static int lg_run(void) return -1; } + // setup the spice startup condition + if (!(e_spice = lgCreateEvent(false, 0))) + { + DEBUG_ERROR("failed to create the spice startup event"); + return -1; + } + // setup the startup condition if (!(e_startup = lgCreateEvent(false, 0))) { @@ -1227,6 +1238,10 @@ static int lg_run(void) DEBUG_ERROR("spice create thread failed"); return -1; } + + lgWaitEvent(e_spice, TIMEOUT_INFINITE); + if (!g_state.spiceReady) + return -1; } // select and init a renderer @@ -1664,6 +1679,12 @@ static void lg_shutdown(void) e_startup = NULL; } + if (e_spice) + { + lgFreeEvent(e_spice); + e_startup = NULL; + } + if (g_state.ds) g_state.ds->shutdown();