mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 07:21:14 +01:00
Merge pull request #12719 from stblr/device-change-again
HIDv4: Fix racy device change behavior
This commit is contained in:
commit
b98176075e
@ -94,11 +94,12 @@ std::optional<IPCReply> USB_HIDv4::GetDeviceChange(const IOCtlRequest& request)
|
|||||||
return IPCReply(IPC_EINVAL);
|
return IPCReply(IPC_EINVAL);
|
||||||
|
|
||||||
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(GetSystem(), request.address);
|
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(GetSystem(), request.address);
|
||||||
// On the first call, the reply is sent immediately (instead of on device insertion/removal)
|
// If there are pending changes, the reply is sent immediately (instead of on device
|
||||||
if (m_devicechange_first_call)
|
// insertion/removal).
|
||||||
|
if (m_has_pending_changes)
|
||||||
{
|
{
|
||||||
TriggerDeviceChangeReply();
|
TriggerDeviceChangeReply();
|
||||||
m_devicechange_first_call = false;
|
m_has_pending_changes = false;
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -138,7 +139,7 @@ s32 USB_HIDv4::SubmitTransfer(USB::Device& device, const IOCtlRequest& request)
|
|||||||
|
|
||||||
void USB_HIDv4::DoState(PointerWrap& p)
|
void USB_HIDv4::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
p.Do(m_devicechange_first_call);
|
p.Do(m_has_pending_changes);
|
||||||
u32 hook_address = m_devicechange_hook_request ? m_devicechange_hook_request->address : 0;
|
u32 hook_address = m_devicechange_hook_request ? m_devicechange_hook_request->address : 0;
|
||||||
p.Do(hook_address);
|
p.Do(hook_address);
|
||||||
if (hook_address != 0)
|
if (hook_address != 0)
|
||||||
@ -199,7 +200,10 @@ bool USB_HIDv4::ShouldAddDevice(const USB::Device& device) const
|
|||||||
void USB_HIDv4::TriggerDeviceChangeReply()
|
void USB_HIDv4::TriggerDeviceChangeReply()
|
||||||
{
|
{
|
||||||
if (!m_devicechange_hook_request)
|
if (!m_devicechange_hook_request)
|
||||||
|
{
|
||||||
|
m_has_pending_changes = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& system = GetSystem();
|
auto& system = GetSystem();
|
||||||
auto& memory = system.GetMemory();
|
auto& memory = system.GetMemory();
|
||||||
|
@ -44,7 +44,7 @@ private:
|
|||||||
static constexpr u32 VERSION = 0x40001;
|
static constexpr u32 VERSION = 0x40001;
|
||||||
static constexpr u8 HID_CLASS = 0x03;
|
static constexpr u8 HID_CLASS = 0x03;
|
||||||
|
|
||||||
bool m_devicechange_first_call = true;
|
bool m_has_pending_changes = true;
|
||||||
std::mutex m_devicechange_hook_address_mutex;
|
std::mutex m_devicechange_hook_address_mutex;
|
||||||
std::unique_ptr<IOCtlRequest> m_devicechange_hook_request;
|
std::unique_ptr<IOCtlRequest> m_devicechange_hook_request;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user