ControllerInterface: Add RemoveDevice()

This adds RemoveDevice() to ControllerInterface, fixes ExpressionParser
and some other code to support device removals without crashing,
and adds an IsValid() method to Device, to prepare for hotplugging.
This commit is contained in:
Léo Lam
2016-07-14 17:45:59 +02:00
parent 0d783f0869
commit 93f5df4195
13 changed files with 69 additions and 19 deletions

View File

@ -6,8 +6,19 @@
#include <memory>
#include "Common/Common.h"
// This should be called before calling GetState() or State() on a control reference
// to prevent a race condition.
// This is a recursive mutex because UpdateReferences is recursive.
static std::recursive_mutex s_get_state_mutex;
std::unique_lock<std::recursive_mutex> ControllerEmu::GetStateLock()
{
std::unique_lock<std::recursive_mutex> lock(s_get_state_mutex);
return lock;
}
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
{
auto lock = ControllerEmu::GetStateLock();
for (auto& ctrlGroup : groups)
{
for (auto& control : ctrlGroup->controls)