Zhiyi Zhang : dinput: Fix a possible deadlock at exit.
Module: wine Branch: stable Commit: cf4883de1354df1061b4834b4d99615dfe8dedfb URL: https://source.winehq.org/git/wine.git/?a=commit;h=cf4883de1354df1061b4834b4... Author: Zhiyi Zhang <zzhang(a)codeweavers.com> Date: Thu Apr 11 18:28:40 2019 +0800 dinput: Fix a possible deadlock at exit. This fix another deadlock issue with dinput. The old implementation of dinput waits for a hook thread to exit during its uninitialization, which will never return during DLL_THREAD_DETACH. Signed-off-by: Zhiyi Zhang <zzhang(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> (cherry picked from commit 886d28de974b0b012be87cf8552806dc65ef3ea9) Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org> --- dlls/dinput/dinput_main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 65aaf92..1b2020c 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1781,7 +1781,7 @@ static DWORD WINAPI hook_thread_proc(void *param) DispatchMessageW(&msg); } - return 0; + FreeLibraryAndExitThread(DINPUT_instance, 0); } static DWORD hook_thread_id; @@ -1798,15 +1798,16 @@ static CRITICAL_SECTION dinput_hook_crit = { &dinput_critsect_debug, -1, 0, 0, 0 static BOOL check_hook_thread(void) { static HANDLE hook_thread; + HMODULE module; EnterCriticalSection(&dinput_hook_crit); TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list)); if (!list_empty(&direct_input_list) && !hook_thread) { + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)DINPUT_instance, &module); hook_thread_event = CreateEventW(NULL, FALSE, FALSE, NULL); hook_thread = CreateThread(NULL, 0, hook_thread_proc, hook_thread_event, 0, &hook_thread_id); - LeaveCriticalSection(&dinput_hook_crit); } else if (list_empty(&direct_input_list) && hook_thread) { @@ -1821,16 +1822,11 @@ static BOOL check_hook_thread(void) hook_thread_id = 0; PostThreadMessageW(tid, WM_USER+0x10, 0, 0); - LeaveCriticalSection(&dinput_hook_crit); - - /* wait for hook thread to exit */ - WaitForSingleObject(hook_thread, INFINITE); CloseHandle(hook_thread); hook_thread = NULL; } - else - LeaveCriticalSection(&dinput_hook_crit); + LeaveCriticalSection(&dinput_hook_crit); return hook_thread_id != 0; }
participants (1)
-
Alexandre Julliard