InputCommon: Fix deadlock in EmulatedController::UpdateReferences(). #11040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
There's a deadlock here that can happen if thread A calls
UpdateReferences()while thread B holds theDeviceContainer::m_devices_mutexand before releasing it also callsUpdateReferences(). TheUpdateReferences()first locks thes_get_state_mutex, then locks them_devices_mutex(indirectly first via theHasConnectedDevice()call, but also potentially later down theUpdateReferences()chain in eg.ControlExpression::UpdateReferences()). Ifm_devices_mutexis already locked by another thread that subsequently tries to acquire thes_get_state_mutex-- for example, the HotkeyScheduler thread callingUpdateInput()which in turn triggers aInvokeDevicesChangedCallbacks()which in turn also triggersUpdateReferences()-- they both try to lock the mutex the other thread already holds, deadlocking in the process.This is the deadlock I mentioned in #11038.