From: "Rémi Bernon" Subject: [PATCH 2/8] dinput: Hold the internal CS while processing hook notifications. Message-Id: <20220105135842.718365-2-rbernon@codeweavers.com> Date: Wed, 5 Jan 2022 14:58:36 +0100 In-Reply-To: <20220105135842.718365-1-rbernon@codeweavers.com> References: <20220105135842.718365-1-rbernon@codeweavers.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52263 Signed-off-by: Rémi Bernon --- dlls/dinput/dinput_main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 980edeba817..e2fabfc75f0 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1275,9 +1275,10 @@ static DWORD WINAPI dinput_thread_proc( void *params ) { UINT kbd_cnt = 0, mice_cnt = 0; + EnterCriticalSection( &dinput_hook_crit ); + if (ret < events_count) { - EnterCriticalSection( &dinput_hook_crit ); LIST_FOR_EACH_ENTRY_SAFE( impl, next, &acquired_device_list, struct dinput_device, entry ) { if (impl->read_event == events[ret]) @@ -1287,7 +1288,6 @@ static DWORD WINAPI dinput_thread_proc( void *params ) break; } } - LeaveCriticalSection( &dinput_hook_crit ); } while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) @@ -1308,13 +1308,12 @@ static DWORD WINAPI dinput_thread_proc( void *params ) if (kbd_hook) UnhookWindowsHookEx( kbd_hook ); if (mouse_hook) UnhookWindowsHookEx( mouse_hook ); kbd_hook = mouse_hook = NULL; + LeaveCriticalSection( &dinput_hook_crit ); goto done; } - EnterCriticalSection( &dinput_hook_crit ); kbd_cnt = list_count( &acquired_keyboard_list ); mice_cnt = list_count( &acquired_mouse_list ); - LeaveCriticalSection( &dinput_hook_crit ); if (kbd_cnt && !kbd_hook) kbd_hook = SetWindowsHookExW( WH_KEYBOARD_LL, LL_hook_proc, NULL, 0 ); @@ -1336,13 +1335,13 @@ static DWORD WINAPI dinput_thread_proc( void *params ) } events_count = 0; - EnterCriticalSection( &dinput_hook_crit ); LIST_FOR_EACH_ENTRY( impl, &acquired_device_list, struct dinput_device, entry ) { if (!impl->read_event || !impl->vtbl->read) continue; if (events_count >= ARRAY_SIZE(events)) break; events[events_count++] = impl->read_event; } + LeaveCriticalSection( &dinput_hook_crit ); } -- 2.34.1