mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -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:
@ -40,11 +40,6 @@ set(SRCS
|
||||
Logging/LogManager.cpp
|
||||
)
|
||||
|
||||
if(LIBUSB_FOUND)
|
||||
set(LIBS ${LIBS} ${LIBUSB_LIBRARIES})
|
||||
set(SRCS ${SRCS} LibusbContext.cpp)
|
||||
endif(LIBUSB_FOUND)
|
||||
|
||||
if(ANDROID)
|
||||
set(SRCS ${SRCS}
|
||||
Logging/ConsoleListenerDroid.cpp)
|
||||
|
@ -118,7 +118,6 @@
|
||||
<ClInclude Include="Hash.h" />
|
||||
<ClInclude Include="IniFile.h" />
|
||||
<ClInclude Include="JitRegister.h" />
|
||||
<ClInclude Include="LibusbContext.h" />
|
||||
<ClInclude Include="LinearDiskCache.h" />
|
||||
<ClInclude Include="MathUtil.h" />
|
||||
<ClInclude Include="MD5.h" />
|
||||
@ -170,9 +169,6 @@
|
||||
<ClCompile Include="Hash.cpp" />
|
||||
<ClCompile Include="IniFile.cpp" />
|
||||
<ClCompile Include="JitRegister.cpp" />
|
||||
<ClCompile Include="LibusbContext.cpp">
|
||||
<DisableSpecificWarnings>4200;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Logging\ConsoleListenerWin.cpp" />
|
||||
<ClCompile Include="MathUtil.cpp" />
|
||||
<ClCompile Include="MD5.cpp" />
|
||||
|
@ -49,7 +49,6 @@
|
||||
<ClInclude Include="FPURoundMode.h" />
|
||||
<ClInclude Include="Hash.h" />
|
||||
<ClInclude Include="IniFile.h" />
|
||||
<ClInclude Include="LibusbContext.h" />
|
||||
<ClInclude Include="LinearDiskCache.h" />
|
||||
<ClInclude Include="MathUtil.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
@ -251,7 +250,6 @@
|
||||
<ClCompile Include="FileUtil.cpp" />
|
||||
<ClCompile Include="Hash.cpp" />
|
||||
<ClCompile Include="IniFile.cpp" />
|
||||
<ClCompile Include="LibusbContext.cpp" />
|
||||
<ClCompile Include="MathUtil.cpp" />
|
||||
<ClCompile Include="MemArena.cpp" />
|
||||
<ClCompile Include="MemoryUtil.cpp" />
|
||||
|
@ -1,49 +0,0 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <libusb.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "Common/LibusbContext.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
namespace LibusbContext
|
||||
{
|
||||
static std::shared_ptr<libusb_context> s_libusb_context;
|
||||
static std::once_flag s_context_initialized;
|
||||
|
||||
static libusb_context* Create()
|
||||
{
|
||||
libusb_context* context;
|
||||
const int ret = libusb_init(&context);
|
||||
if (ret < LIBUSB_SUCCESS)
|
||||
{
|
||||
bool is_windows = false;
|
||||
#ifdef _WIN32
|
||||
is_windows = true;
|
||||
#endif
|
||||
const std::string reason =
|
||||
is_windows && ret == LIBUSB_ERROR_NOT_FOUND ?
|
||||
GetStringT("Failed to initialize libusb because usbdk is not installed.") :
|
||||
StringFromFormat(GetStringT("Failed to initialize libusb (%s).").c_str(),
|
||||
libusb_error_name(ret));
|
||||
PanicAlertT("%s\nSome USB features will not work.", reason.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
std::shared_ptr<libusb_context> Get()
|
||||
{
|
||||
std::call_once(s_context_initialized, []() {
|
||||
s_libusb_context.reset(Create(), [](auto* context) {
|
||||
if (context != nullptr)
|
||||
libusb_exit(context);
|
||||
});
|
||||
});
|
||||
return s_libusb_context;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct libusb_context;
|
||||
|
||||
namespace LibusbContext
|
||||
{
|
||||
// libusb on Windows is limited to only a single context. Trying to open more
|
||||
// than one can cause issues with device enumerations.
|
||||
// libusb is thread-safe so this context can be safely used from different threads.
|
||||
std::shared_ptr<libusb_context> Get();
|
||||
}
|
Reference in New Issue
Block a user