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/utils/src/push_log.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/utils/src/push_log.cc')
-rw-r--r-- | src/components/utils/src/push_log.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/components/utils/src/push_log.cc b/src/components/utils/src/push_log.cc index 6e16c99181..dea0e75274 100644 --- a/src/components/utils/src/push_log.cc +++ b/src/components/utils/src/push_log.cc @@ -36,8 +36,12 @@ namespace logger { -static bool logs_enabled_ = false; -static LogMessageLoopThread* log_message_loop_thread = NULL; +struct __attribute__((visibility("default"))) LogsEnabled { + static std::atomic_bool logs_enabled_; +}; + +std::atomic_bool LogsEnabled::logs_enabled_(false); +static std::unique_ptr<LogMessageLoopThread> log_message_loop_thread; bool push_log(log4cxx::LoggerPtr logger, log4cxx::LevelPtr level, @@ -73,22 +77,22 @@ bool push_log(log4cxx::LoggerPtr logger, } bool logs_enabled() { - return logs_enabled_; + return LogsEnabled::logs_enabled_; } void set_logs_enabled(bool state) { - logs_enabled_ = state; + LogsEnabled::logs_enabled_ = state; } void create_log_message_loop_thread() { if (!log_message_loop_thread) { - log_message_loop_thread = new LogMessageLoopThread(); + log_message_loop_thread = + std::unique_ptr<LogMessageLoopThread>(new LogMessageLoopThread); } } void delete_log_message_loop_thread() { - delete log_message_loop_thread; - log_message_loop_thread = NULL; + log_message_loop_thread.reset(); } void flush_logger() { |