From 890d1b812a9477b434486ab503c15dd3fce3e964 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 3 Apr 2019 11:39:36 +0800 Subject: [PATCH] dinput: Do not wait for hook thread startup in IDirectInput8::Initialize. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=21403 Signed-off-by: Zhiyi Zhang Signed-off-by: Alexandre Julliard --- dlls/dinput/dinput_main.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 54777da2d96..66dc6e34b2a 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1719,7 +1719,7 @@ static DWORD WINAPI hook_thread_proc(void *param) /* Force creation of the message queue */ PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ); - SetEvent(*(LPHANDLE)param); + SetEvent(param); while (GetMessageW( &msg, 0, 0, 0 )) { @@ -1785,6 +1785,7 @@ static DWORD WINAPI hook_thread_proc(void *param) } static DWORD hook_thread_id; +static HANDLE hook_thread_event; static CRITICAL_SECTION_DEBUG dinput_critsect_debug = { @@ -1803,24 +1804,21 @@ static BOOL check_hook_thread(void) TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list)); if (!list_empty(&direct_input_list) && !hook_thread) { - HANDLE event; - - event = CreateEventW(NULL, FALSE, FALSE, NULL); - hook_thread = CreateThread(NULL, 0, hook_thread_proc, &event, 0, &hook_thread_id); - if (event && hook_thread) - { - HANDLE handles[2]; - handles[0] = event; - handles[1] = hook_thread; - WaitForMultipleObjects(2, handles, FALSE, INFINITE); - } + 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); - CloseHandle(event); } else if (list_empty(&direct_input_list) && hook_thread) { DWORD tid = hook_thread_id; + if (hook_thread_event) /* if thread is not started yet */ + { + WaitForSingleObject(hook_thread_event, INFINITE); + CloseHandle(hook_thread_event); + hook_thread_event = NULL; + } + hook_thread_id = 0; PostThreadMessageW(tid, WM_USER+0x10, 0, 0); LeaveCriticalSection(&dinput_hook_crit); @@ -1861,6 +1859,13 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface) callwndproc_hook = NULL; } + if (hook_thread_event) /* if thread is not started yet */ + { + WaitForSingleObject(hook_thread_event, INFINITE); + CloseHandle(hook_thread_event); + hook_thread_event = NULL; + } + PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, 0 ); LeaveCriticalSection(&dinput_hook_crit);