diff options
author | Andriy Byzhynar <abyzhynar@luxoft.com> | 2019-11-08 16:13:38 +0200 |
---|---|---|
committer | Andriy Byzhynar <abyzhynar@luxoft.com> | 2019-11-08 16:13:38 +0200 |
commit | 76ad6b3e9ab67733a53a9ca73023655d305904fd (patch) | |
tree | cfe918db2606da80992a31a6811efa33dfc7bf42 | |
parent | 891497bc9fb23434242dbe92e1f13dd1273fcb21 (diff) | |
download | sdl_core-fix/seg_fault_TM_UT.tar.gz |
Reworked usb handler delegate completionfix/seg_fault_TM_UT
-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 |