Commit 54e6f5c2 authored by Natsu's avatar Natsu Committed by Alexander Alekhin

Merge pull request #15970 from akemimadoka:master

* Fix android armv7 c++_static init crash

* core: move initialization of 'ios_base::Init' for Android
parent ca282748
...@@ -21,6 +21,8 @@ namespace logging { ...@@ -21,6 +21,8 @@ namespace logging {
static LogLevel parseLogLevelConfiguration() static LogLevel parseLogLevelConfiguration()
{ {
(void)getInitializationMutex(); // ensure initialization of global objects
static cv::String param_log_level = utils::getConfigurationParameterString("OPENCV_LOG_LEVEL", static cv::String param_log_level = utils::getConfigurationParameterString("OPENCV_LOG_LEVEL",
#if defined NDEBUG #if defined NDEBUG
"WARNING" "WARNING"
......
...@@ -55,11 +55,26 @@ ...@@ -55,11 +55,26 @@
namespace cv { namespace cv {
static void _initSystem()
{
#ifdef __ANDROID__
// https://github.com/opencv/opencv/issues/14906
// "ios_base::Init" object is not a part of Android's "iostream" header (in case of clang toolchain, NDK 20).
// Ref1: https://en.cppreference.com/w/cpp/io/ios_base/Init
// The header <iostream> behaves as if it defines (directly or indirectly) an instance of std::ios_base::Init with static storage duration
// Ref2: https://github.com/gcc-mirror/gcc/blob/gcc-8-branch/libstdc%2B%2B-v3/include/std/iostream#L73-L74
static std::ios_base::Init s_iostream_initializer;
#endif
}
static Mutex* __initialization_mutex = NULL; static Mutex* __initialization_mutex = NULL;
Mutex& getInitializationMutex() Mutex& getInitializationMutex()
{ {
if (__initialization_mutex == NULL) if (__initialization_mutex == NULL)
{
(void)_initSystem();
__initialization_mutex = new Mutex(); __initialization_mutex = new Mutex();
}
return *__initialization_mutex; return *__initialization_mutex;
} }
// force initialization (single-threaded environment) // force initialization (single-threaded environment)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment