Fixed thread handling.

This commit is contained in:
Armin Novak 2013-09-05 13:39:43 +02:00
parent 8ae13cdace
commit c5a632d8f9

View File

@ -569,7 +569,10 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam)
rdpChannels* channels;
instance = (freerdp*) lpParam;
assert(NULL != instance);
wfc = (wfContext*) instance->context;
assert(NULL != wfc);
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(wfds, sizeof(wfds));
@ -690,13 +693,13 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam)
}
/* cleanup */
wfc->mainThreadId = 0;
freerdp_channels_close(channels, instance);
freerdp_disconnect(instance);
printf("Main thread exited.\n");
ExitThread(0);
return 0;
}
@ -708,6 +711,7 @@ DWORD WINAPI wf_keyboard_thread(LPVOID lpParam)
HHOOK hook_handle;
wfc = (wfContext*) lpParam;
assert(NULL != wfc);
hook_handle = SetWindowsHookEx(WH_KEYBOARD_LL, wf_ll_kbd_proc, wfc->hInstance, 0);
@ -734,9 +738,9 @@ DWORD WINAPI wf_keyboard_thread(LPVOID lpParam)
fprintf(stderr, "failed to install keyboard hook\n");
}
wfc->keyboardThreadId = 0;
printf("Keyboard thread exited.\n");
ExitThread(0);
return (DWORD) NULL;
}
@ -1078,12 +1082,27 @@ int wfreerdp_client_stop(rdpContext* context)
{
wfContext* wfc = (wfContext*) context;
if (wfc->mainThreadId)
if (wfc->thread)
{
PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0);
if (wfc->keyboardThreadId)
WaitForSingleObject(wfc->thread, INFINITE);
CloseHandle(wfc->thread);
wfc->thread = NULL;
wfc->mainThreadId = 0;
}
if (wfc->keyboardThread)
{
PostThreadMessage(wfc->keyboardThreadId, WM_QUIT, 0, 0);
WaitForSingleObject(wfc->keyboardThread, INFINITE);
CloseHandle(wfc->keyboardThread);
wfc->keyboardThread = NULL;
wfc->keyboardThreadId = 0;
}
return 0;
}