Avoid deadlock when adding Wiimotes (attempt #2)

Signed-off-by: Jonathan Dieter <jdieter@lesbg.com>
This commit is contained in:
Jonathan Dieter 2015-05-06 21:53:53 +03:00
parent 72956d59c8
commit 3fe839d225

View File

@ -829,7 +829,10 @@ void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32
// Read the Wiimote once
void Update(int _WiimoteNumber)
{
std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
// Try to get a lock and return without doing anything if we fail
// This avoids deadlocks when adding a Wiimote during continuous scan
if(!g_refresh_lock.try_lock())
return;
if (g_wiimotes[_WiimoteNumber])
g_wiimotes[_WiimoteNumber]->Update();
@ -839,6 +842,7 @@ void Update(int _WiimoteNumber)
{
Host_ConnectWiimote(_WiimoteNumber, false);
}
g_refresh_lock.unlock();
}
void StateChange(EMUSTATE_CHANGE newState)