diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2017-03-26 14:51:12 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2017-03-26 15:58:30 +0200 |
| commit | 32a1b5068ad61bb025ef28f8bc3bdf81af9bf581 (patch) | |
| tree | 2c78b2386160e9f0bb316e530058abce3192a615 /Source/Core/InputCommon/GCAdapter.cpp | |
| parent | 6c62cfb1aa248d9106f5a70ecf690dd320028365 (diff) | |
Revert "Use a single libusb context"
This reverts commit c8a6dc6c23a5efe99b4bf937003ba3f2f7f8f200.
libusb on Windows isn't really safe to use from different threads
with a single context.
Diffstat (limited to 'Source/Core/InputCommon/GCAdapter.cpp')
| -rw-r--r-- | Source/Core/InputCommon/GCAdapter.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index 1b251b3f5e..5916ab600f 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -4,11 +4,9 @@ #include <algorithm> #include <libusb.h> -#include <memory> #include <mutex> #include "Common/Flag.h" -#include "Common/LibusbContext.h" #include "Common/Logging/Log.h" #include "Common/Thread.h" #include "Core/ConfigManager.h" @@ -52,7 +50,7 @@ static Common::Flag s_adapter_detect_thread_running; static std::function<void(void)> s_detect_callback; static bool s_libusb_driver_not_supported = false; -static std::shared_ptr<libusb_context> s_libusb_context; +static libusb_context* s_libusb_context; #if defined(__FreeBSD__) && __FreeBSD__ >= 11 static bool s_libusb_hotplug_enabled = true; #else @@ -118,8 +116,8 @@ static void ScanThreadFunc() if (s_libusb_hotplug_enabled) { if (libusb_hotplug_register_callback( - s_libusb_context.get(), (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | - LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), + s_libusb_context, (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), LIBUSB_HOTPLUG_ENUMERATE, 0x057e, 0x0337, LIBUSB_HOTPLUG_MATCH_ANY, HotplugCallback, nullptr, &s_hotplug_handle) != LIBUSB_SUCCESS) s_libusb_hotplug_enabled = false; @@ -133,7 +131,7 @@ static void ScanThreadFunc() if (s_libusb_hotplug_enabled) { static timeval tv = {0, 500000}; - libusb_handle_events_timeout(s_libusb_context.get(), &tv); + libusb_handle_events_timeout(s_libusb_context, &tv); } else { @@ -179,9 +177,12 @@ void StartScanThread() if (s_adapter_detect_thread_running.IsSet()) return; - s_libusb_context = LibusbContext::Get(); - if (!s_libusb_context) + const int ret = libusb_init(&s_libusb_context); + if (ret < 0) + { + ERROR_LOG(SERIALINTERFACE, "libusb_init failed with error: %d", ret); return; + } s_adapter_detect_thread_running.Set(true); s_adapter_detect_thread = std::thread(ScanThreadFunc); } @@ -197,7 +198,7 @@ void StopScanThread() static void Setup() { libusb_device** list; - ssize_t cnt = libusb_get_device_list(s_libusb_context.get(), &list); + ssize_t cnt = libusb_get_device_list(s_libusb_context, &list); for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; i++) { @@ -329,11 +330,15 @@ void Shutdown() StopScanThread(); #if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 if (s_libusb_context && s_libusb_hotplug_enabled) - libusb_hotplug_deregister_callback(s_libusb_context.get(), s_hotplug_handle); + libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle); #endif Reset(); - s_libusb_context.reset(); + if (s_libusb_context) + { + libusb_exit(s_libusb_context); + s_libusb_context = nullptr; + } s_libusb_driver_not_supported = false; } |
