diff options
author | Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com> | 2019-11-18 16:43:27 +0200 |
---|---|---|
committer | Shobhit Adlakha <ShobhitAd@users.noreply.github.com> | 2019-11-18 09:43:27 -0500 |
commit | 60b57cd8db748a49ec33a11b22b28d919a1bb850 (patch) | |
tree | de83cff4d110704f50d73a3cdaf3c424981eff04 | |
parent | 2eafae9d0ae0b352d3b30bd1409bebdcfc447988 (diff) | |
download | sdl_core-60b57cd8db748a49ec33a11b22b28d919a1bb850.tar.gz |
Reworked usb handler delegate completion (#3121)
-rw-r--r-- | src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h | 1 | ||||
-rw-r--r-- | src/components/transport_manager/src/usb/libusb/usb_handler.cc | 20 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h index 6b15229522..9c16b49df6 100644 --- a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h +++ b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h @@ -76,6 +76,7 @@ class UsbHandler { public: explicit UsbHandlerDelegate(UsbHandler* handler); void threadMain() OVERRIDE; + void exitThreadMain() OVERRIDE; private: UsbHandler* handler_; 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 |