[client] added ivshmem_process thread and fixed shutdown behaviour

This commit is contained in:
Geoffrey McRae
2017-10-19 18:50:42 +11:00
parent 327a3a77cf
commit 3a7bff77f2
3 changed files with 64 additions and 12 deletions

View File

@@ -327,13 +327,32 @@ int renderThread(void * unused)
return 0;
}
int ivshmemThread(void * arg)
{
while(state.running)
if (!ivshmem_process())
{
if (state.running)
{
state.running = false;
DEBUG_ERROR("failed to process ivshmem messages");
}
break;
}
return 0;
}
int spiceThread(void * arg)
{
while(state.running)
if (!spice_process())
{
state.running = false;
DEBUG_ERROR("Failed to process spice messages");
if (state.running)
{
state.running = false;
DEBUG_ERROR("failed to process spice messages");
}
break;
}
@@ -463,9 +482,10 @@ int main(int argc, char * argv[])
memset(&state, 0, sizeof(state));
state.running = true;
int shm_fd = 0;
SDL_Thread *t_spice = NULL;
SDL_Thread *t_event = NULL;
int shm_fd = 0;
SDL_Thread *t_ivshmem = NULL;
SDL_Thread *t_spice = NULL;
SDL_Thread *t_event = NULL;
while(1)
{
@@ -475,6 +495,12 @@ int main(int argc, char * argv[])
break;
}
if (!(t_ivshmem = SDL_CreateThread(ivshmemThread, "ivshmemThread", NULL)))
{
DEBUG_ERROR("ivshmem create thread failed");
break;
}
state.shm = (struct KVMGFXHeader *)ivshmem_get_map();
if (!state.shm)
{
@@ -519,6 +545,12 @@ int main(int argc, char * argv[])
if (t_event)
SDL_WaitThread(t_event, NULL);
// this needs to happen here to abort any waiting reads
// as ivshmem uses recvmsg which has no timeout
ivshmem_disconnect();
if (t_ivshmem)
SDL_WaitThread(t_ivshmem, NULL);
if (t_spice)
SDL_WaitThread(t_spice, NULL);