diff options
| author | Dentomologist <dentomologist@gmail.com> | 2023-03-08 16:58:55 -0800 |
|---|---|---|
| committer | Dentomologist <dentomologist@gmail.com> | 2023-03-08 17:22:27 -0800 |
| commit | d6a8e6caaf1edfec74f3c41518cfb8e095f36bdc (patch) | |
| tree | 304e141e651e18308ef066bc1225b7a81fe89e07 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | 560a23957c7bef98a782ef6e7a73da06dc540a8b (diff) | |
ControllerInterface: Fix deadlock when Wii Remote disconnects
In UpdateInput, lock m_devices_population_mutex before m_devices_mutex
to be consistent with other ControllerInterface functions. Normally the
former lock isn't needed in UpdateInput, but when a Wii Remote
disconnects it calls RemoveDevice which results in the mutexes being
locked in the wrong order.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 6a6affd478..f9c4aa5bc0 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -372,6 +372,14 @@ void ControllerInterface::UpdateInput() // TODO: if we are an emulation input channel, we should probably always lock // Prefer outdated values over blocking UI or CPU thread (avoids short but noticeable frame drop) + + // Lock this first to avoid deadlock with m_devices_mutex in certain cases (such as a Wii Remote + // getting disconnected) + if (!m_devices_population_mutex.try_lock()) + return; + + std::lock_guard population_lock(m_devices_population_mutex, std::adopt_lock); + if (!m_devices_mutex.try_lock()) return; |
