Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9020 from Tilka/usb
IOS/USB: fix potential race condition
  • Loading branch information
leoetlino committed Aug 17, 2020
2 parents c994567 + ee0d466 commit 6104018
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 23 deletions.
8 changes: 5 additions & 3 deletions Source/Core/Core/IOS/USB/Host.cpp
Expand Up @@ -31,7 +31,10 @@ USBHost::USBHost(Kernel& ios, const std::string& device_name) : Device(ios, devi
{
}

USBHost::~USBHost() = default;
USBHost::~USBHost()
{
StopThreads();
}

IPCCommandResult USBHost::Open(const OpenRequest& request)
{
Expand Down Expand Up @@ -179,9 +182,8 @@ void USBHost::StartThreads()
if (Core::WantsDeterminism())
return;

if (!m_scan_thread_running.IsSet())
if (m_scan_thread_running.TestAndSet())
{
m_scan_thread_running.Set();
m_scan_thread = std::thread([this] {
Common::SetCurrentThreadName("USB Scan Thread");
while (m_scan_thread_running.IsSet())
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/IOS/USB/Host.h
Expand Up @@ -53,13 +53,14 @@ class USBHost : public Device
virtual void OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> changed_device);
virtual void OnDeviceChangeEnd();
virtual bool ShouldAddDevice(const USB::Device& device) const;
void StartThreads();
void StopThreads();

IPCCommandResult HandleTransfer(std::shared_ptr<USB::Device> device, u32 request,
std::function<s32()> submit) const;

private:
void StartThreads();
void StopThreads();

bool AddDevice(std::unique_ptr<USB::Device> device);
bool UpdateDevices(bool always_add_hooks = false);

Expand Down
5 changes: 0 additions & 5 deletions Source/Core/Core/IOS/USB/OH0/OH0.cpp
Expand Up @@ -26,11 +26,6 @@ OH0::OH0(Kernel& ios, const std::string& device_name) : USBHost(ios, device_name
{
}

OH0::~OH0()
{
StopThreads();
}

IPCCommandResult OH0::Open(const OpenRequest& request)
{
if (HasFeature(m_ios.GetVersion(), Feature::NewUSB))
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/IOS/USB/OH0/OH0.h
Expand Up @@ -37,7 +37,6 @@ class OH0 final : public USBHost
{
public:
OH0(Kernel& ios, const std::string& device_name);
~OH0() override;

IPCCommandResult Open(const OpenRequest& request) override;
IPCCommandResult IOCtl(const IOCtlRequest& request) override;
Expand Down
5 changes: 0 additions & 5 deletions Source/Core/Core/IOS/USB/USBV5.cpp
Expand Up @@ -86,11 +86,6 @@ struct DeviceEntry
#pragma pack(pop)
} // namespace

USBV5ResourceManager::~USBV5ResourceManager()
{
StopThreads();
}

void USBV5ResourceManager::DoState(PointerWrap& p)
{
p.Do(m_devicechange_first_call);
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/IOS/USB/USBV5.h
Expand Up @@ -69,7 +69,6 @@ class USBV5ResourceManager : public USBHost
{
public:
using USBHost::USBHost;
~USBV5ResourceManager() override;

IPCCommandResult IOCtl(const IOCtlRequest& request) override = 0;
IPCCommandResult IOCtlV(const IOCtlVRequest& request) override = 0;
Expand Down
5 changes: 0 additions & 5 deletions Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp
Expand Up @@ -26,11 +26,6 @@ USB_HIDv4::USB_HIDv4(Kernel& ios, const std::string& device_name) : USBHost(ios,
{
}

USB_HIDv4::~USB_HIDv4()
{
StopThreads();
}

IPCCommandResult USB_HIDv4::IOCtl(const IOCtlRequest& request)
{
request.Log(GetDeviceName(), Common::Log::IOS_USB);
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/IOS/USB/USB_HID/HIDv4.h
Expand Up @@ -22,7 +22,6 @@ class USB_HIDv4 final : public USBHost
{
public:
USB_HIDv4(Kernel& ios, const std::string& device_name);
~USB_HIDv4() override;

IPCCommandResult IOCtl(const IOCtlRequest& request) override;

Expand Down

0 comments on commit 6104018

Please sign in to comment.