diff options
author | Alexander Kutsan (GitHub) <akutsan@luxoft.com> | 2019-08-22 23:08:12 +0300 |
---|---|---|
committer | Collin <iCollin@users.noreply.github.com> | 2019-08-22 16:08:12 -0400 |
commit | 8db0c2601921fdd368bf86133780746b532c40f5 (patch) | |
tree | fd76b6fc43ab46ac571d06f95c2ce0cea04509e3 /src/components/transport_manager/src/usb/libusb/usb_handler.cc | |
parent | 0e57834d35230ddbe395096ace053414e811b980 (diff) | |
download | sdl_core-8db0c2601921fdd368bf86133780746b532c40f5.tar.gz |
Fix shutdown crash static var colission (#2939)
* Add apropriate destruction of plugins
Add Delete exported function to each rpc plugin library
Delete funciton will destroy Plugin instance.
Move type defenition of PluginPtr to Plugin manager, because other components should use olugins only by referance.
Add custom destructor for PluginPtr.
custom destructor will call `Delete` function from shared library for plugin instance and unload plugin dl_handle.
Deprecate GetPlugins method because it not used (and actualy shouldnt) by other components.
Refactored LoadPlugin function, make it more readable, make this function as private RPCPluginManagerImpl private method.
* Fix components dependencies after hiding libraries symbols
* Add `-fvisibility=hidden` to avoid collision of static variables
Remove from ABI all shared objects members except functions that needed.
Fixes double destruction crash on shutdown.
For the case if dynamically linked library contains same static variables as binary.
System allocates the same memory for both static variables (in shared object and in binary).
But during exit both binary and shared object destroying this memory.
Mostly is a specific for binaries generated by gcc compiler.
Inspired by https://stackoverflow.com/questions/3570355/c-fvisibility-hidden-fvisibility-inlines-hidden
http://gcc.gnu.org/wiki/Visibility
* Link Policy code statically
SDL components like Application manager Connection Handler, etc ...
requires symbols from policy library.
Also policy library loaded by SDL in run-time as shared library.
Having same library loaded as dynamic and shared library is definitely bad idea.
This commit link extract static policy component and link policy component statically to other components.
* Static linkage of plugins code un plugins unit tests
Unit tests need to be portable and should not depend from dynamic libraries
* Put logs_enabled_ "default" visibility attribute
Logs enables is static variable and it should be shared across
libraries.
On SDL start if set_enabled_logs should put value shared across
libraries
* Changed the order of destruction of objects
Changed the order of destruction of objects to avoid the crash during destruction of the RequestController.
* Change the order of the waiting and finishing thread
Applications using hotplug support
should stop the thread at program exit
and wait finishing thread after calling
libusb_hotplug_deregister_callback.
This call wakes up libusb_handle_events ()
http://libusb.sourceforge.net/api-1.0/group__libusb__asyncio.html
* fixup! Add apropriate destruction of plugins
* Make saftly usage of logger
Added usage unique_ptr for
LogMessageLoopThread to avoid
the crash when
delete_log_message_loop_thread
was not fired.
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 | 12 |
1 files changed, 6 insertions, 6 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 df3b7e128e..975f71e84c 100644 --- a/src/components/transport_manager/src/usb/libusb/usb_handler.cc +++ b/src/components/transport_manager/src/usb/libusb/usb_handler.cc @@ -90,20 +90,20 @@ UsbHandler::UsbHandler() UsbHandler::~UsbHandler() { shutdown_requested_ = true; - if (libusb_context_ != 0) { + thread_->stop(); + LOG4CXX_INFO(logger_, "UsbHandler thread finished"); + if (libusb_context_ != 0) { // This wakes up libusb_handle_events() libusb_hotplug_deregister_callback(libusb_context_, arrived_callback_handle_); libusb_hotplug_deregister_callback(libusb_context_, left_callback_handle_); } - thread_->stop(); - LOG4CXX_INFO(logger_, "UsbHandler thread finished"); + thread_->join(); + delete thread_->delegate(); + threads::DeleteThread(thread_); if (libusb_context_) { libusb_exit(libusb_context_); libusb_context_ = 0; } - thread_->join(); - delete thread_->delegate(); - threads::DeleteThread(thread_); } void UsbHandler::DeviceArrived(libusb_device* device_libusb) { |