ControllerInterface: fix rare deadlock

A "devices changed" callback could have ended up waiting on another thread that was also populating devices
and waiting on the previous thread to release the callbacks mutex.
This commit is contained in:
Filoppi 2021-05-15 11:25:20 +03:00
parent ebe3fbe04c
commit c285ae57fb
1 changed files with 4 additions and 2 deletions

View File

@ -322,7 +322,9 @@ void ControllerInterface::UnregisterDevicesChangedCallback(const HotplugCallback
// Invoke all callbacks that were registered
void ControllerInterface::InvokeDevicesChangedCallbacks() const
{
std::lock_guard<std::mutex> lk(m_callbacks_mutex);
for (const auto& callback : m_devices_changed_callbacks)
m_callbacks_mutex.lock();
const auto devices_changed_callbacks = m_devices_changed_callbacks;
m_callbacks_mutex.unlock();
for (const auto& callback : devices_changed_callbacks)
callback();
}