[PATCH 8/8] dinput: Keep a module reference with the internal thread.
Rémi Bernon
rbernon at codeweavers.com
Wed Jan 5 07:58:42 CST 2022
Instead of waiting for the thread on process detach.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52263
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/dinput/dinput_main.c | 33 +++++----------------------------
1 file changed, 5 insertions(+), 28 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 764eada6762..dfa7712ac09 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -78,8 +78,6 @@ HINSTANCE DINPUT_instance;
static HWND di_em_win;
-static HANDLE dinput_thread;
-
static CRITICAL_SECTION dinput_hook_crit;
static CRITICAL_SECTION_DEBUG dinput_critsect_debug =
{
@@ -1314,15 +1312,6 @@ static DWORD WINAPI dinput_thread_proc( void *params )
TRACE( "Processing hook change notification wp:%ld lp:%#lx\n", msg.wParam, msg.lParam );
- if (!msg.wParam)
- {
- if (kbd_hook) UnhookWindowsHookEx( kbd_hook );
- if (mouse_hook) UnhookWindowsHookEx( mouse_hook );
- di_em_win = 0;
- LeaveCriticalSection( &dinput_hook_crit );
- goto done;
- }
-
kbd_cnt = list_count( &acquired_keyboard_list );
mice_cnt = list_count( &acquired_mouse_list );
@@ -1380,12 +1369,15 @@ done:
DestroyWindow( hwnd );
TRACE( "exiting internal thread\n" );
- return 0;
+ FreeLibraryAndExitThread( DINPUT_instance, 0 );
}
static void dinput_thread_start(void)
{
HANDLE start_event, thread;
+ HMODULE module;
+
+ GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)DINPUT_instance, &module );
start_event = CreateEventW( NULL, FALSE, FALSE, NULL );
if (!start_event) ERR( "failed to create start event, error %u\n", GetLastError() );
@@ -1395,21 +1387,7 @@ static void dinput_thread_start(void)
else WaitForSingleObject( start_event, INFINITE );
CloseHandle( start_event );
- CloseHandle( dinput_thread );
- dinput_thread = thread;
-}
-
-static void dinput_thread_stop(void)
-{
- HANDLE thread = NULL;
-
- EnterCriticalSection( &dinput_hook_crit );
- PostMessageW( di_em_win, WM_USER + 0x10, 0, 0 );
- thread = dinput_thread;
- dinput_thread = NULL;
- LeaveCriticalSection( &dinput_hook_crit );
-
- WaitForSingleObject( thread, INFINITE );
+ if (!thread) FreeLibrary( module );
CloseHandle( thread );
}
@@ -1502,7 +1480,6 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved)
break;
case DLL_PROCESS_DETACH:
if (reserved) break;
- dinput_thread_stop();
unregister_di_em_win_class();
DeleteCriticalSection(&dinput_hook_crit);
break;
--
2.34.1
More information about the wine-devel
mailing list