提交 ef2b7304 编写于 作者: A Alexander Alekhin

Merge pull request #9342 from alalek:fix_parallel_for

......@@ -363,6 +363,10 @@ static SchedPtr pplScheduler;
/* ================================ parallel_for_ ================================ */
#ifdef CV_PARALLEL_FRAMEWORK
static void parallel_for_impl(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes); // forward declaration
#endif
void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
{
#ifdef OPENCV_TRACE
......@@ -377,10 +381,35 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
return;
#ifdef CV_PARALLEL_FRAMEWORK
static volatile int flagNestedParallelFor = 0;
bool isNotNestedRegion = flagNestedParallelFor == 0;
if (isNotNestedRegion)
isNotNestedRegion = CV_XADD(&flagNestedParallelFor, 1) == 0;
if (isNotNestedRegion)
{
try
{
parallel_for_impl(range, body, nstripes);
flagNestedParallelFor = 0;
}
catch (...)
{
flagNestedParallelFor = 0;
throw;
}
}
else // nested parallel_for_() calls are not parallelized
#endif // CV_PARALLEL_FRAMEWORK
{
(void)nstripes;
body(range);
}
}
static int flagNestedParallelFor = 0;
bool isNotNesterParallelFor = CV_XADD(&flagNestedParallelFor, 1) == 0;
if(numThreads != 0 && isNotNesterParallelFor)
#ifdef CV_PARALLEL_FRAMEWORK
static void parallel_for_impl(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
{
if ((numThreads < 0 || numThreads > 1) && range.end - range.start > 1)
{
ParallelLoopBodyWrapperContext ctx(body, range, nstripes);
ProxyLoopBody pbody(ctx);
......@@ -388,7 +417,6 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
if( stripeRange.end - stripeRange.start == 1 )
{
body(range);
flagNestedParallelFor = 0;
return;
}
......@@ -444,16 +472,14 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
#error You have hacked and compiling with unsupported parallel framework
#endif
flagNestedParallelFor = 0;
}
else
#endif // CV_PARALLEL_FRAMEWORK
{
(void)nstripes;
body(range);
}
}
#endif // CV_PARALLEL_FRAMEWORK
int cv::getNumThreads(void)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册