Sebastian Lackner : dinput: Do not wait for hook thread startup in IDirectInput8::Initialize.

Alexandre Julliard julliard at winehq.org
Fri Aug 23 09:31:25 CDT 2019


Module: wine
Branch: stable
Commit: 6eb596c5e8044bd57c2a71ed28f97755e1d6f0ae
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=6eb596c5e8044bd57c2a71ed28f97755e1d6f0ae

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Wed Apr  3 11:39:36 2019 +0800

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 <zzhang at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 890d1b812a9477b434486ab503c15dd3fce3e964)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 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 54777da..66dc6e3 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);




More information about the wine-cvs mailing list