From b2ef4a806bd5f8f81917a7c93d210cee123191af Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Thu, 18 Sep 2014 19:00:56 +0200 Subject: [PATCH] qeditor: initialise libusb once in a static ctor Change-Id: Ic93def2b3633c498c9863b0dada3281853be8c6c Reviewed-on: http://gerrit.rockbox.org/973 Reviewed-by: Amaury Pouly --- utils/regtools/qeditor/backend.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/utils/regtools/qeditor/backend.cpp b/utils/regtools/qeditor/backend.cpp index 86e4d60ef9..570ae4d01f 100644 --- a/utils/regtools/qeditor/backend.cpp +++ b/utils/regtools/qeditor/backend.cpp @@ -356,7 +356,6 @@ bool HWStubIoBackend::Reload() */ HWStubBackendHelper::HWStubBackendHelper() { - libusb_init(NULL); #ifdef LIBUSB_NO_HOTPLUG m_hotplug = false; #else @@ -371,7 +370,7 @@ HWStubBackendHelper::HWStubBackendHelper() &HWStubBackendHelper::HotPlugCallback, reinterpret_cast< void* >(this), &m_hotplug_handle); } -#endif +#endif /* LIBUSB_NO_HOTPLUG */ } HWStubBackendHelper::~HWStubBackendHelper() @@ -379,7 +378,7 @@ HWStubBackendHelper::~HWStubBackendHelper() #ifndef LIBUSB_NO_HOTPLUG if(m_hotplug) libusb_hotplug_deregister_callback(NULL, m_hotplug_handle); -#endif +#endif /* LIBUSB_NO_HOTPLUG */ } QList< HWStubDevice* > HWStubBackendHelper::GetDevList() @@ -420,14 +419,28 @@ int HWStubBackendHelper::HotPlugCallback(struct libusb_context *ctx, struct libu } return 0; } -#endif +#endif /* LIBUSB_NO_HOTPLUG */ bool HWStubBackendHelper::HasHotPlugSupport() { return m_hotplug; } -#endif +namespace +{ +class lib_usb_init +{ +public: + lib_usb_init() + { + libusb_init(NULL); + } +}; + +lib_usb_init __lib_usb_init; +} + +#endif /* HAVE_HWSTUB */ /** * BackendHelper