mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 15:55:31 +01:00
Merge pull request #10512 from stblr/device-change
USBv5: Fix racy device change behavior
This commit is contained in:
commit
c883ec1c53
@ -85,7 +85,7 @@ struct DeviceEntry
|
|||||||
|
|
||||||
void USBV5ResourceManager::DoState(PointerWrap& p)
|
void USBV5ResourceManager::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)
|
||||||
@ -119,11 +119,12 @@ std::optional<IPCReply> USBV5ResourceManager::GetDeviceChange(const IOCtlRequest
|
|||||||
|
|
||||||
std::lock_guard lk{m_devicechange_hook_address_mutex};
|
std::lock_guard lk{m_devicechange_hook_address_mutex};
|
||||||
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(request.address);
|
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(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;
|
||||||
}
|
}
|
||||||
@ -226,7 +227,10 @@ void USBV5ResourceManager::OnDeviceChangeEnd()
|
|||||||
void USBV5ResourceManager::TriggerDeviceChangeReply()
|
void USBV5ResourceManager::TriggerDeviceChangeReply()
|
||||||
{
|
{
|
||||||
if (!m_devicechange_hook_request)
|
if (!m_devicechange_hook_request)
|
||||||
|
{
|
||||||
|
m_has_pending_changes = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::lock_guard lock{m_usbv5_devices_mutex};
|
std::lock_guard lock{m_usbv5_devices_mutex};
|
||||||
u8 num_devices = 0;
|
u8 num_devices = 0;
|
||||||
|
@ -89,7 +89,7 @@ protected:
|
|||||||
void TriggerDeviceChangeReply();
|
void TriggerDeviceChangeReply();
|
||||||
virtual bool HasInterfaceNumberInIDs() const = 0;
|
virtual bool HasInterfaceNumberInIDs() const = 0;
|
||||||
|
|
||||||
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