core(parallel): fix plugins handling if no filesystem available
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 18 Mar 2021 22:58:05 +0000 (22:58 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 18 Mar 2021 23:05:12 +0000 (23:05 +0000)
modules/core/CMakeLists.txt
modules/core/src/parallel/parallel.cpp
modules/core/src/parallel/registry_parallel.impl.hpp

index 3dcd019..b2797ab 100644 (file)
@@ -18,8 +18,12 @@ ocv_add_dispatched_file_force_all(test_intrin256 TEST AVX2 AVX512_SKX)
 ocv_add_dispatched_file_force_all(test_intrin512 TEST AVX512_SKX)
 
 
+set(PARALLEL_ENABLE_PLUGINS_DEFAULT ON)
+if(EMSCRIPTEN OR IOS OR WINRT)
+  set(PARALLEL_ENABLE_PLUGINS_DEFAULT OFF)
+endif()
 # parallel backends configuration
-set(PARALLEL_ENABLE_PLUGINS "ON" CACHE BOOL "Allow building parallel plugin support")
+set(PARALLEL_ENABLE_PLUGINS "${PARALLEL_ENABLE_PLUGINS_DEFAULT}" CACHE BOOL "Allow building parallel plugin support")
 # TODO building plugins with OpenCV is not supported yet
 #set(PARALLEL_PLUGIN_LIST "" CACHE STRING "List of parallel backends to be compiled as plugins (tbb, openmp or special value 'all')")
 #string(REPLACE "," ";" PARALLEL_PLUGIN_LIST "${PARALLEL_PLUGIN_LIST}")  # support comma-separated list (,) too
index 67fea67..29b482f 100644 (file)
@@ -63,7 +63,11 @@ std::shared_ptr<ParallelForAPI> createParallelForAPI()
         try
         {
             CV_LOG_DEBUG(NULL, "core(parallel): trying backend: " << info.name << " (priority=" << info.priority << ")");
-            CV_Assert(info.backendFactory);
+            if (!info.backendFactory)
+            {
+                CV_LOG_DEBUG(NULL, "core(parallel): factory is not available (plugins require filesystem support): " << info.name);
+                continue;
+            }
             std::shared_ptr<ParallelForAPI> backend = info.backendFactory->create();
             if (!backend)
             {
index ef51437..c8b57e7 100644 (file)
@@ -6,17 +6,23 @@
 // Not a standalone header, part of parallel.cpp
 //
 
+#include "opencv2/core/utils/filesystem.private.hpp"  // OPENCV_HAVE_FILESYSTEM_SUPPORT
+
 namespace cv { namespace parallel {
 
+#if OPENCV_HAVE_FILESYSTEM_SUPPORT && defined(PARALLEL_ENABLE_PLUGINS)
 #define DECLARE_DYNAMIC_BACKEND(name) \
 ParallelBackendInfo { \
     1000, name, createPluginParallelBackendFactory(name) \
-}
+},
+#else
+#define DECLARE_DYNAMIC_BACKEND(name) /* nothing */
+#endif
 
 #define DECLARE_STATIC_BACKEND(name, createBackendAPI) \
 ParallelBackendInfo { \
     1000, name, std::make_shared<cv::parallel::StaticBackendFactory>([=] () -> std::shared_ptr<cv::parallel::ParallelForAPI> { return createBackendAPI(); }) \
-}
+},
 
 static
 std::vector<ParallelBackendInfo>& getBuiltinParallelBackendsInfo()
@@ -24,14 +30,14 @@ std::vector<ParallelBackendInfo>& getBuiltinParallelBackendsInfo()
     static std::vector<ParallelBackendInfo> g_backends
     {
 #ifdef HAVE_TBB
-        DECLARE_STATIC_BACKEND("TBB", createParallelBackendTBB),
+        DECLARE_STATIC_BACKEND("TBB", createParallelBackendTBB)
 #elif defined(PARALLEL_ENABLE_PLUGINS)
-        DECLARE_DYNAMIC_BACKEND("ONETBB"),  // dedicated oneTBB plugin (interface >= 12000, binary incompatibe with TBB 2017-2020)
-        DECLARE_DYNAMIC_BACKEND("TBB"),     // generic TBB plugins
+        DECLARE_DYNAMIC_BACKEND("ONETBB")   // dedicated oneTBB plugin (interface >= 12000, binary incompatibe with TBB 2017-2020)
+        DECLARE_DYNAMIC_BACKEND("TBB")      // generic TBB plugins
 #endif
 
 #ifdef HAVE_OPENMP
-        DECLARE_STATIC_BACKEND("OPENMP", createParallelBackendOpenMP),
+        DECLARE_STATIC_BACKEND("OPENMP", createParallelBackendOpenMP)
 #elif defined(PARALLEL_ENABLE_PLUGINS)
         DECLARE_DYNAMIC_BACKEND("OPENMP")  // TODO Intel OpenMP?
 #endif