[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;
if (this->cursorEvents[0])
{
lgSignalEvent(this->cursorEvents[0]);
this->cursorEvents[0] = NULL;
}
if (this->frameEvent)
{
lgSignalEvent(this->frameEvent);
this->frameEvent = NULL;
}
lgSignalEvent(this->cursorEvents[0]);
lgSignalEvent(this->frameEvent);
if (this->pointerThread)
{

View File

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

View File

@ -146,7 +146,6 @@ static int appThread(void * opaque)
int result = app_main(app.argc, app.argv);
Shell_NotifyIcon(NIM_DELETE, &app.iconData);
mouseHook_remove();
SendMessage(app.messageWnd, WM_DESTROY, 0, 0);
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 Start ] ====");
return startThreads();
return true;
}
static bool captureStop(void)
{
DEBUG_INFO("==== [ Capture Stop ] ====");
if (!stopThreads())
return false;
if (!app.iface->deinit())
{
@ -293,11 +291,6 @@ static bool captureStop(void)
return true;
}
static bool captureRestart(void)
{
return captureStop() && captureStart();
}
bool captureGetPointerBuffer(void ** data, uint32_t * size)
{
PLGMPMemory mem = app.pointerMemory[app.pointerIndex];
@ -570,6 +563,10 @@ int app_main(int argc, char * argv[])
if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer))
{
DEBUG_ERROR("Failed to create the LGMP timer");
iface->deinit();
iface->free();
goto fail_timer;
}
@ -583,6 +580,12 @@ int app_main(int argc, char * argv[])
exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture;
}
if (!startThreads())
{
exitcode = LG_HOST_EXIT_FAILED;
goto fail_threads;
}
}
else
{
@ -596,12 +599,30 @@ int app_main(int argc, char * argv[])
{
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;
stopThreads();
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;
}
@ -632,12 +653,32 @@ int app_main(int argc, char * argv[])
}
if (app.state != APP_STATE_SHUTDOWN)
{
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;
stopThreads();
fail_threads:
captureStop();
fail_capture:
lgTimerDestroy(app.lgmpTimer);
@ -645,9 +686,6 @@ fail_capture:
fail_timer:
LG_LOCK_FREE(app.pointerLock);
iface->deinit();
iface->free();
fail_lgmp:
for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
lgmpHostMemFree(&app.frameMemory[i]);