ControllerInterface: Don't block on UpdateInput()

Changes UpdateInput() to skip if we can't lock the mutex, instead of
potentially blocking the CPU thread and causing a short but noticeable
frame drop.
This commit is contained in:
Léo Lam 2016-07-15 11:34:18 +02:00
parent 93f5df4195
commit 3926db624d
1 changed files with 7 additions and 3 deletions

View File

@ -175,9 +175,13 @@ void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::De
//
void ControllerInterface::UpdateInput()
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
for (const auto& d : m_devices)
d->UpdateInput();
// Don't block the UI or CPU thread (to avoid a short but noticeable frame drop)
if (m_devices_mutex.try_lock())
{
std::lock_guard<std::mutex> lk(m_devices_mutex, std::adopt_lock);
for (const auto& d : m_devices)
d->UpdateInput();
}
}
//