mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Revert "Use a single libusb context"
This reverts commit c8a6dc6c23
.
libusb on Windows isn't really safe to use from different threads
with a single context.
This commit is contained in:
@ -2,23 +2,14 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef __LIBUSB__
|
||||
#include <libusb.h>
|
||||
#include "Common/LibusbContext.h"
|
||||
#endif
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "UICommon/USBUtils.h"
|
||||
|
||||
#ifdef __LIBUSB__
|
||||
static std::once_flag s_tried_libusb_init;
|
||||
static std::shared_ptr<libusb_context> s_libusb_context;
|
||||
#endif
|
||||
|
||||
// Because opening and getting the device name from devices is slow, especially on Windows
|
||||
// with usbdk, we cannot do that for every single device. We should however still show
|
||||
// device names for known Wii peripherals.
|
||||
@ -43,12 +34,12 @@ std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
|
||||
std::map<std::pair<u16, u16>, std::string> devices;
|
||||
|
||||
#ifdef __LIBUSB__
|
||||
std::call_once(s_tried_libusb_init, []() { s_libusb_context = LibusbContext::Get(); });
|
||||
if (!s_libusb_context)
|
||||
libusb_context* context = nullptr;
|
||||
if (libusb_init(&context) < 0)
|
||||
return devices;
|
||||
|
||||
libusb_device** list;
|
||||
const ssize_t cnt = libusb_get_device_list(s_libusb_context.get(), &list);
|
||||
const ssize_t cnt = libusb_get_device_list(context, &list);
|
||||
for (ssize_t i = 0; i < cnt; ++i)
|
||||
{
|
||||
libusb_device_descriptor descr;
|
||||
@ -57,6 +48,7 @@ std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
|
||||
devices[vid_pid] = GetDeviceName(vid_pid);
|
||||
}
|
||||
libusb_free_device_list(list, 1);
|
||||
libusb_exit(context);
|
||||
#endif
|
||||
|
||||
return devices;
|
||||
|
Reference in New Issue
Block a user