diff options
Diffstat (limited to 'src/components/transport_manager/src/usb/libusb/usb_handler.cc')
-rw-r--r-- | src/components/transport_manager/src/usb/libusb/usb_handler.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/components/transport_manager/src/usb/libusb/usb_handler.cc b/src/components/transport_manager/src/usb/libusb/usb_handler.cc index 975f71e84c..d1fc0af7f7 100644 --- a/src/components/transport_manager/src/usb/libusb/usb_handler.cc +++ b/src/components/transport_manager/src/usb/libusb/usb_handler.cc @@ -77,12 +77,12 @@ class UsbHandler::ControlTransferSequenceState { UsbHandler::UsbHandler() : shutdown_requested_(false) - , thread_(NULL) + , thread_(nullptr) , usb_device_listeners_() , devices_() , transfer_sequences_() , device_handles_to_close_() - , libusb_context_(NULL) + , libusb_context_(nullptr) , arrived_callback_handle_() , left_callback_handle_() { thread_ = threads::CreateThread("UsbHandler", new UsbHandlerDelegate(this)); @@ -90,19 +90,23 @@ UsbHandler::UsbHandler() UsbHandler::~UsbHandler() { shutdown_requested_ = true; - thread_->stop(); LOG4CXX_INFO(logger_, "UsbHandler thread finished"); - if (libusb_context_ != 0) { // This wakes up libusb_handle_events() + + if (libusb_context_) { + // The libusb_hotplug_deregister_callback() wakes up blocking call of + // libusb_handle_events_completed() in the Thread() method of delegate libusb_hotplug_deregister_callback(libusb_context_, arrived_callback_handle_); libusb_hotplug_deregister_callback(libusb_context_, left_callback_handle_); } + thread_->join(); delete thread_->delegate(); threads::DeleteThread(thread_); + if (libusb_context_) { libusb_exit(libusb_context_); - libusb_context_ = 0; + libusb_context_ = nullptr; } } @@ -518,5 +522,11 @@ void UsbHandler::UsbHandlerDelegate::threadMain() { handler_->Thread(); } +void UsbHandler::UsbHandlerDelegate::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); + // Empty method required in order to avoid force delegate thread + // finishing by exitThreadMain() of the base class +} + } // namespace transport_adapter } // namespace transport_manager |