Sebastian Lackner : dinput: Avoid deadlock when CS are acquired in different order.

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


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

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Mon Apr  8 03:48:16 2019 +0000

dinput: Avoid deadlock when CS are acquired in different order.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=43356
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 02f0342833f6a6affced820519003d954681a7b4)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/dinput/device.c         | 8 ++++----
 dlls/dinput/dinput_main.c    | 4 ++--
 dlls/dinput/dinput_private.h | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 322c8ac..6c44616 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -994,9 +994,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
     EnterCriticalSection(&This->crit);
     res = This->acquired ? S_FALSE : DI_OK;
     This->acquired = 1;
-    if (res == DI_OK)
-        check_dinput_hooks(iface);
     LeaveCriticalSection(&This->crit);
+    if (res == DI_OK)
+        check_dinput_hooks(iface, TRUE);
 
     return res;
 }
@@ -1022,9 +1022,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
     EnterCriticalSection(&This->crit);
     res = !This->acquired ? DI_NOEFFECT : DI_OK;
     This->acquired = 0;
-    if (res == DI_OK)
-        check_dinput_hooks(iface);
     LeaveCriticalSection(&This->crit);
+    if (res == DI_OK)
+        check_dinput_hooks(iface, FALSE);
 
     return res;
 }
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 66dc6e3..65aaf92 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -1834,7 +1834,7 @@ static BOOL check_hook_thread(void)
     return hook_thread_id != 0;
 }
 
-void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface)
+void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
 {
     static HHOOK callwndproc_hook;
     static ULONG foreground_cnt;
@@ -1844,7 +1844,7 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface)
 
     if (dev->dwCoopLevel & DISCL_FOREGROUND)
     {
-        if (dev->acquired)
+        if (acquired)
             foreground_cnt++;
         else
             foreground_cnt--;
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index abdfbeb..acda6c8 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -71,7 +71,7 @@ extern const struct dinput_device joystick_linux_device DECLSPEC_HIDDEN;
 extern const struct dinput_device joystick_linuxinput_device DECLSPEC_HIDDEN;
 extern const struct dinput_device joystick_osx_device DECLSPEC_HIDDEN;
 
-extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W) DECLSPEC_HIDDEN;
+extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W, BOOL) DECLSPEC_HIDDEN;
 extern void check_dinput_events(void) DECLSPEC_HIDDEN;
 typedef int (*DI_EVENT_PROC)(LPDIRECTINPUTDEVICE8A, WPARAM, LPARAM);
 




More information about the wine-cvs mailing list