[client] fix race segfault on pointer queue unsubscribe/timeout

This commit is contained in:
Geoffrey McRae 2022-01-26 17:20:12 +11:00
parent fb4bdaee2b
commit efa49391fc
3 changed files with 19 additions and 1 deletions

View File

@ -484,12 +484,23 @@ void core_handleMouseNormal(double ex, double ey)
g_cursor.realigning = true;
do
{
LG_LOCK(g_state.pointerQueueLock);
if (!g_state.pointerQueue)
{
/* the queue is nolonger valid, assume complete */
g_cursor.realigning = false;
LG_UNLOCK(g_state.pointerQueueLock);
break;
}
uint32_t hostSerial;
if (lgmpClientGetSerial(g_state.pointerQueue, &hostSerial) != LGMP_OK)
{
g_cursor.realigning = false;
LG_UNLOCK(g_state.pointerQueueLock);
return;
}
LG_UNLOCK(g_state.pointerQueueLock);
if (hostSerial >= setPosSerial)
break;

View File

@ -502,8 +502,9 @@ int main_cursorThread(void * unused)
lgSignalEvent(g_state.frameEvent);
}
LG_LOCK(g_state.pointerQueueLock);
lgmpClientUnsubscribe(&g_state.pointerQueue);
LG_UNLOCK(g_state.pointerQueueLock);
if (cursor)
{
@ -1484,8 +1485,12 @@ restart:
g_state.kvmfrFeatures = udata->features;
LG_LOCK_INIT(g_state.pointerQueueLock);
if (!core_startCursorThread() || !core_startFrameThread())
{
LG_LOCK_FREE(g_state.pointerQueueLock);
return -1;
}
while(g_state.state == APP_STATE_RUNNING)
{
@ -1514,6 +1519,7 @@ restart:
goto restart;
}
LG_LOCK_FREE(g_state.pointerQueueLock);
return 0;
}

View File

@ -113,6 +113,7 @@ struct AppState
struct IVSHMEM shm;
PLGMPClient lgmp;
PLGMPClientQueue pointerQueue;
LG_Lock pointerQueueLock;
KVMFRFeatureFlags kvmfrFeatures;
LGThread * cursorThread;