1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 #include "../precomp.hpp"
5
6 #include "factory_parallel.hpp"
7
8 #ifdef HAVE_TBB
9
10 #include "parallel.hpp"
11 #include "opencv2/core/parallel/backend/parallel_for.tbb.hpp"
12
13 namespace cv { namespace parallel {
14
15 static
getInstance()16 std::shared_ptr<cv::parallel::tbb::ParallelForBackend>& getInstance()
17 {
18 static std::shared_ptr<cv::parallel::tbb::ParallelForBackend> g_instance = std::make_shared<cv::parallel::tbb::ParallelForBackend>();
19 return g_instance;
20 }
21
22 #ifndef BUILD_PLUGIN
createParallelBackendTBB()23 std::shared_ptr<cv::parallel::ParallelForAPI> createParallelBackendTBB()
24 {
25 return getInstance();
26 }
27 #endif
28
29 }} // namespace
30
31 #ifdef BUILD_PLUGIN
32
33 #define ABI_VERSION 0
34 #define API_VERSION 0
35 #include "plugin_parallel_api.hpp"
36
37 static
cv_getInstance(CV_OUT CvPluginParallelBackendAPI * handle)38 CvResult cv_getInstance(CV_OUT CvPluginParallelBackendAPI* handle) CV_NOEXCEPT
39 {
40 try
41 {
42 if (!handle)
43 return CV_ERROR_FAIL;
44 *handle = cv::parallel::getInstance().get();
45 return CV_ERROR_OK;
46 }
47 catch (...)
48 {
49 return CV_ERROR_FAIL;
50 }
51 }
52
53 static const OpenCV_Core_Parallel_Plugin_API plugin_api =
54 {
55 {
56 sizeof(OpenCV_Core_Parallel_Plugin_API), ABI_VERSION, API_VERSION,
57 CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS,
58 "TBB (interface " CVAUX_STR(TBB_INTERFACE_VERSION) ") OpenCV parallel plugin"
59 },
60 {
61 /* 1*/cv_getInstance
62 }
63 };
64
opencv_core_parallel_plugin_init_v0(int requested_abi_version,int requested_api_version,void *)65 const OpenCV_Core_Parallel_Plugin_API* CV_API_CALL opencv_core_parallel_plugin_init_v0(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
66 {
67 if (requested_abi_version == ABI_VERSION && requested_api_version <= API_VERSION)
68 return &plugin_api;
69 return NULL;
70 }
71
72 #endif // BUILD_PLUGIN
73
74 #endif // HAVE_TBB
75