Rémi Bernon : dinput: Start and cancel reading HID reports while holding the CS.

Alexandre Julliard julliard at winehq.org
Fri Oct 1 18:02:22 CDT 2021


Module: wine
Branch: master
Commit: 9a9a1656c1a154425b920168bbdd5aaaa3b27d22
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9a9a1656c1a154425b920168bbdd5aaaa3b27d22

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Fri Oct  1 09:31:03 2021 +0200

dinput: Start and cancel reading HID reports while holding the CS.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/joystick_hid.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index aee8118191f..b6c4c960521 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -699,14 +699,18 @@ static HRESULT WINAPI hid_joystick_Acquire( IDirectInputDevice8W *iface )
 
     TRACE( "iface %p.\n", iface );
 
-    if ((hr = IDirectInputDevice2WImpl_Acquire( iface )) != DI_OK) return hr;
-
-    memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) );
-    impl->read_ovl.hEvent = impl->base.read_event;
-    if (ReadFile( impl->device, impl->input_report_buf, report_len, NULL, &impl->read_ovl ))
-        impl->base.read_callback( iface );
+    EnterCriticalSection( &impl->base.crit );
+    hr = IDirectInputDevice2WImpl_Acquire( iface );
+    if (hr == DI_OK)
+    {
+        memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) );
+        impl->read_ovl.hEvent = impl->base.read_event;
+        if (ReadFile( impl->device, impl->input_report_buf, report_len, NULL, &impl->read_ovl ))
+            impl->base.read_callback( iface );
+    }
+    LeaveCriticalSection( &impl->base.crit );
 
-    return DI_OK;
+    return hr;
 }
 
 static HRESULT WINAPI hid_joystick_Unacquire( IDirectInputDevice8W *iface )
@@ -717,12 +721,16 @@ static HRESULT WINAPI hid_joystick_Unacquire( IDirectInputDevice8W *iface )
 
     TRACE( "iface %p.\n", iface );
 
-    if ((hr = IDirectInputDevice2WImpl_Unacquire( iface )) != DI_OK) return hr;
-
-    ret = CancelIoEx( impl->device, &impl->read_ovl );
-    if (!ret) WARN( "CancelIoEx failed, last error %u\n", GetLastError() );
+    EnterCriticalSection( &impl->base.crit );
+    if (impl->base.acquired)
+    {
+        ret = CancelIoEx( impl->device, &impl->read_ovl );
+        if (!ret) WARN( "CancelIoEx failed, last error %u\n", GetLastError() );
+    }
+    hr = IDirectInputDevice2WImpl_Unacquire( iface );
+    LeaveCriticalSection( &impl->base.crit );
 
-    return DI_OK;
+    return hr;
 }
 
 static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr )




More information about the wine-cvs mailing list