dolphin/Source/Core/InputCommon
Dentomologist c613d3ca10 ControllerInterface: Fix Windows deadlock
Remove the redundant s_populate_mutex and only use
ControllerInterface::m_devices_population_mutex instead to prevent a
deadlock caused by locking them in opposite orders.

The device population functions in the win32 InputBackend previously
locked s_populate_mutex first before calling various functions that
locked m_devices_population_mutex. This normally worked but
ControllerInterface::RefreshDevices locks m_devices_population_mutex
first and then calls HandleWindowChange which then locked
s_populate_mutex, potentially causing the deadlock.

Fix this by using PlatformPopulateDevices to lock
m_devices_population_mutex before running the code that was previously
protected by s_populate_mutex. The functions in question lock
m_devices_population_mutex anyway, so this shouldn't meaningfully
increase contention on the lock.

Reproduction steps:

* Let Dolphin finish startup.
* In Win32.cpp::OnDevicesChanged set a breakpoint on the call to
  PlatformPopulateDevices. When the breakpoint is triggered the function
  will have locked s_populate_mutex, but since PlatformPopulateDevices
  won't have run yet m_devices_population_mutex will still be unlocked.
* Unplug a device from your computer.
* Wait for the breakpoint to trigger. (At this point you can plug the
  device back in).
* Freeze the ntdll.dll!TppWorkerThread() that triggered the breakpoint.
* Resume Dolphin and start a game.
* Core::EmuThread will call ControllerInterface::ChangeWindow which
  calls RefreshDevices. It locks m_devices_population_mutex, then calls
  InputBackend::HandleWindowChange, which tries to lock
  s_populate_mutex.
* Unfreeze ntdll.dll!TppWorkerThread().

At this point EmuThread and TppWorkerThread are deadlocked. The UI is
still responsive since the Host thread is unaffected, but trying to stop
the game or close Dolphin normally will fail since EmuThread is unable
to stop.
2025-06-28 14:00:27 -07:00
..
ControlReference Source: Remove redundant lambda parameter lists 2025-06-14 10:19:31 +02:00
ControllerEmu Merge pull request #13702 from CostPerUnit/master 2025-06-09 00:09:35 -04:00
ControllerInterface ControllerInterface: Fix Windows deadlock 2025-06-28 14:00:27 -07:00
DynamicInputTextures Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
CMakeLists.txt InputCommon: Update to use SDL3 and bump the SDL submodule in Externals to release-3.2.16. 2025-06-07 16:27:54 -05:00
DynamicInputTextureManager.cpp Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
DynamicInputTextureManager.h Common/IniFile: Move interface into Common namespace 2023-04-13 10:19:28 -04:00
GCAdapter.cpp LibusbDevice: Don't detach kernel drivers on macOS 2025-02-01 10:32:20 +13:00
GCAdapter.h GCAdapter: Process pad state in read thread and other general cleanups. 2022-10-22 00:38:59 -05:00
GCPadStatus.h Fix all uninitialized variable warnings (C26495) 2021-10-13 12:32:16 -07:00
ImageOperations.cpp Common and VideoCommon: Change texture data from std::vector to Common::UniqueBuffer. 2025-05-03 18:32:30 -05:00
ImageOperations.h C++20: Synthesize `operator!=` From `operator==` 2024-10-10 20:23:55 -07:00
InputConfig.cpp Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
InputConfig.h Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
InputProfile.cpp Modernize `std::set_intersection` with ranges 2024-10-10 00:53:48 -07:00
InputProfile.h treewide: convert GPLv2+ license info to SPDX tags 2021-07-05 04:35:56 +02:00
KeyboardStatus.h treewide: convert GPLv2+ license info to SPDX tags 2021-07-05 04:35:56 +02:00