[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.
This commit is contained in:
Geoffrey McRae 2022-05-27 09:22:10 +10:00
parent b94869249c
commit 1770defea2

View File

@ -69,6 +69,7 @@
static int renderThread(void * unused); static int renderThread(void * unused);
static LGEvent *e_startup = NULL; static LGEvent *e_startup = NULL;
static LGEvent *e_spice = NULL;
static LGThread *t_spice = NULL; static LGThread *t_spice = NULL;
static LGThread *t_render = NULL; static LGThread *t_render = NULL;
@ -888,6 +889,7 @@ void spiceReady(void)
keybind_spiceRegister(); keybind_spiceRegister();
purespice_freeServerInfo(&info); purespice_freeServerInfo(&info);
lgSignalEvent(e_spice);
} }
static void spice_surfaceCreate(unsigned int surfaceId, PSSurfaceFormat format, static void spice_surfaceCreate(unsigned int surfaceId, PSSurfaceFormat format,
@ -987,6 +989,7 @@ int spiceThread(void * arg)
if (!purespice_connect(&config)) if (!purespice_connect(&config))
{ {
DEBUG_ERROR("Failed to connect to spice server"); DEBUG_ERROR("Failed to connect to spice server");
lgSignalEvent(e_spice);
goto end; goto end;
} }
@ -1024,6 +1027,7 @@ end:
if (!g_state.spiceClose) if (!g_state.spiceClose)
g_state.state = APP_STATE_SHUTDOWN; g_state.state = APP_STATE_SHUTDOWN;
lgSignalEvent(e_spice);
return 0; return 0;
} }
@ -1190,6 +1194,13 @@ static int lg_run(void)
return -1; 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 // setup the startup condition
if (!(e_startup = lgCreateEvent(false, 0))) if (!(e_startup = lgCreateEvent(false, 0)))
{ {
@ -1227,6 +1238,10 @@ static int lg_run(void)
DEBUG_ERROR("spice create thread failed"); DEBUG_ERROR("spice create thread failed");
return -1; return -1;
} }
lgWaitEvent(e_spice, TIMEOUT_INFINITE);
if (!g_state.spiceReady)
return -1;
} }
// select and init a renderer // select and init a renderer
@ -1664,6 +1679,12 @@ static void lg_shutdown(void)
e_startup = NULL; e_startup = NULL;
} }
if (e_spice)
{
lgFreeEvent(e_spice);
e_startup = NULL;
}
if (g_state.ds) if (g_state.ds)
g_state.ds->shutdown(); g_state.ds->shutdown();