dolphin/Source/Core/InputCommon/ControllerInterface
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
..
Android Simplify `std::find` with `Common::Contains` 2025-01-01 09:52:03 -08:00
DInput Make overriding explicit and remove redundant virtual specifiers on overriding destructors - Core & UnitTests 2025-05-01 15:00:37 +02:00
DualShockUDPClient Make overriding explicit and remove redundant virtual specifiers on overriding destructors - Core & UnitTests 2025-05-01 15:00:37 +02:00
ForceFeedback InputCommon: Remove some IOKit leftovers. 2024-03-11 01:11:13 -05:00
Pipes InputCommon: Rename AddAnalogInputs to AddFullAnalogSurfaceInputs. 2024-11-03 15:06:50 -06:00
Quartz Use 'contains' method 2024-08-15 14:20:16 -07:00
SDL Merge pull request #13694 from jordan-woyak/sdl3 2025-06-24 18:59:48 -04:00
SteamDeck Make overriding explicit and remove redundant virtual specifiers on overriding destructors - Core & UnitTests 2025-05-01 15:00:37 +02:00
Touch ControllerInterface/Android: Rip out ButtonManager 2023-03-03 22:28:23 +01:00
WGInput linter: Apply clang-format 19.1 formatting 2025-04-23 11:19:20 +02:00
Wiimote Make overriding explicit and remove redundant virtual specifiers on overriding destructors - Core & UnitTests 2025-05-01 15:00:37 +02:00
Win32 ControllerInterface: Fix Windows deadlock 2025-06-28 14:00:27 -07:00
XInput Input: Improve Controller Interface devices threading 2023-12-18 21:45:22 +02:00
Xlib Merge pull request #12850 from jordan-woyak/device-sorting 2024-06-15 21:12:08 +02:00
evdev InputCommon: Rename AddAnalogInputs to AddFullAnalogSurfaceInputs. 2024-11-03 15:06:50 -06:00
ControllerInterface.cpp Modernize `std::stable_sort` with ranges and projections 2025-03-09 13:26:38 -07:00
ControllerInterface.h 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
CoreDevice.cpp InputCommon: Make InputDetector::Start take a span instead of a vector. 2025-06-14 16:28:09 -05:00
CoreDevice.h InputCommon: Make InputDetector::Start take a span instead of a vector. 2025-06-14 16:28:09 -05:00
InputBackend.cpp InputCommon: Add Win32 InputBackend class. 2024-03-11 03:25:31 -05:00
InputBackend.h InputCommon: Add Win32 InputBackend class. 2024-03-11 03:25:31 -05:00
MappingCommon.cpp DolphinQt: Make Calibration autocomplete when data is "sensible" and stick is returned to neutral position. 2025-06-24 02:18:25 -05:00
MappingCommon.h DolphinQt: Make Calibration autocomplete when data is "sensible" and stick is returned to neutral position. 2025-06-24 02:18:25 -05:00