mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40:42 -07:00
rawinput: avoid deadlock when binding analog axis as a button (#809)
## Link to GitHub Issue or related Pull Request, if one exists Regressed by #793 ## Description of change Due to lock inversion, when binding an analog axis as a button, spice deadlocks. Fix that. Also create a separate `unordered_map` that keeps track of device handles so that `WM_INPUT` handle can look up devices without having to acquire the larger `devices_mutex` which could be held by (potentially) lengthy operations like hotplug. Fix more synchronization issues around hotplug. Latent bug exposed by MIDI 2.0 issues. ## Testing
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "device.h"
|
||||
|
||||
namespace rawinput {
|
||||
|
||||
class RawInputHandles {
|
||||
public:
|
||||
struct AcquiredDevice {
|
||||
Device *device = nullptr;
|
||||
std::unique_lock<std::mutex> lock;
|
||||
};
|
||||
|
||||
void add(Device *device);
|
||||
void remove(Device *device);
|
||||
AcquiredDevice acquire(HANDLE handle);
|
||||
|
||||
private:
|
||||
// non-owning index; RawInputManager owns the stable device slots
|
||||
std::unordered_map<HANDLE, Device *> devices;
|
||||
std::mutex mutex;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user