[host] fix faults caused by improper startup/shudown/restart ordering

This commit is contained in:
Geoffrey McRae 2021-01-21 17:05:30 +11:00
parent 6b8161972d
commit 04774d9cd6
4 changed files with 55 additions and 26 deletions

View File

@ -211,17 +211,8 @@ static void nvfbc_stop(void)
{ {
this->stop = true; this->stop = true;
if (this->cursorEvents[0]) lgSignalEvent(this->cursorEvents[0]);
{ lgSignalEvent(this->frameEvent);
lgSignalEvent(this->cursorEvents[0]);
this->cursorEvents[0] = NULL;
}
if (this->frameEvent)
{
lgSignalEvent(this->frameEvent);
this->frameEvent = NULL;
}
if (this->pointerThread) if (this->pointerThread)
{ {

View File

@ -146,6 +146,7 @@ void mouseHook_remove(void)
{ {
if (!mouseHook.event) if (!mouseHook.event)
return; return;
SetEvent(mouseHook.event); SetEvent(mouseHook.event);
WaitForSingleObject(mouseHook.thread, INFINITE); WaitForSingleObject(mouseHook.thread, INFINITE);
CloseHandle(mouseHook.thread); CloseHandle(mouseHook.thread);

View File

@ -146,7 +146,6 @@ static int appThread(void * opaque)
int result = app_main(app.argc, app.argv); int result = app_main(app.argc, app.argv);
Shell_NotifyIcon(NIM_DELETE, &app.iconData); Shell_NotifyIcon(NIM_DELETE, &app.iconData);
mouseHook_remove();
SendMessage(app.messageWnd, WM_DESTROY, 0, 0); SendMessage(app.messageWnd, WM_DESTROY, 0, 0);
return result; return result;
} }

View File

@ -275,14 +275,12 @@ static bool captureStart(void)
DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize); DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize);
DEBUG_INFO("==== [ Capture Start ] ===="); DEBUG_INFO("==== [ Capture Start ] ====");
return startThreads(); return true;
} }
static bool captureStop(void) static bool captureStop(void)
{ {
DEBUG_INFO("==== [ Capture Stop ] ===="); DEBUG_INFO("==== [ Capture Stop ] ====");
if (!stopThreads())
return false;
if (!app.iface->deinit()) if (!app.iface->deinit())
{ {
@ -293,11 +291,6 @@ static bool captureStop(void)
return true; return true;
} }
static bool captureRestart(void)
{
return captureStop() && captureStart();
}
bool captureGetPointerBuffer(void ** data, uint32_t * size) bool captureGetPointerBuffer(void ** data, uint32_t * size)
{ {
PLGMPMemory mem = app.pointerMemory[app.pointerIndex]; PLGMPMemory mem = app.pointerMemory[app.pointerIndex];
@ -570,6 +563,10 @@ int app_main(int argc, char * argv[])
if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer)) if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer))
{ {
DEBUG_ERROR("Failed to create the LGMP timer"); DEBUG_ERROR("Failed to create the LGMP timer");
iface->deinit();
iface->free();
goto fail_timer; goto fail_timer;
} }
@ -583,6 +580,12 @@ int app_main(int argc, char * argv[])
exitcode = LG_HOST_EXIT_FAILED; exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture; goto fail_capture;
} }
if (!startThreads())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_threads;
}
} }
else else
{ {
@ -596,12 +599,30 @@ int app_main(int argc, char * argv[])
{ {
if (app.state == APP_STATE_RESTART) if (app.state == APP_STATE_RESTART)
{ {
if (!captureRestart()) if (!stopThreads())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_threads;
}
if (!captureStop())
{ {
exitcode = LG_HOST_EXIT_FAILED; exitcode = LG_HOST_EXIT_FAILED;
stopThreads();
goto fail_capture; goto fail_capture;
} }
if (!captureStart())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture;
}
if (!startThreads())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_threads;
}
app.state = APP_STATE_RUNNING; app.state = APP_STATE_RUNNING;
} }
@ -632,12 +653,32 @@ int app_main(int argc, char * argv[])
} }
if (app.state != APP_STATE_SHUTDOWN) if (app.state != APP_STATE_SHUTDOWN)
{
DEBUG_INFO("No subscribers, going to sleep..."); DEBUG_INFO("No subscribers, going to sleep...");
captureStop(); if (!stopThreads())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_threads;
}
if (!captureStop())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture;
}
continue;
}
break;
} }
exitcode = app.exitcode; exitcode = app.exitcode;
stopThreads();
fail_threads:
captureStop();
fail_capture: fail_capture:
lgTimerDestroy(app.lgmpTimer); lgTimerDestroy(app.lgmpTimer);
@ -645,9 +686,6 @@ fail_capture:
fail_timer: fail_timer:
LG_LOCK_FREE(app.pointerLock); LG_LOCK_FREE(app.pointerLock);
iface->deinit();
iface->free();
fail_lgmp: fail_lgmp:
for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i) for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
lgmpHostMemFree(&app.frameMemory[i]); lgmpHostMemFree(&app.frameMemory[i]);