@@ -363,6 +363,10 @@ static SchedPtr pplScheduler;
363
363
364
364
/* ================================ parallel_for_ ================================ */
365
365
366
+ #ifdef CV_PARALLEL_FRAMEWORK
367
+ static void parallel_for_impl (const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes); // forward declaration
368
+ #endif
369
+
366
370
void cv::parallel_for_ (const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
367
371
{
368
372
#ifdef OPENCV_TRACE
@@ -377,18 +381,42 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
377
381
return ;
378
382
379
383
#ifdef CV_PARALLEL_FRAMEWORK
384
+ static volatile int flagNestedParallelFor = 0 ;
385
+ bool isNotNestedRegion = flagNestedParallelFor == 0 ;
386
+ if (isNotNestedRegion)
387
+ isNotNestedRegion = CV_XADD (&flagNestedParallelFor, 1 ) == 0 ;
388
+ if (isNotNestedRegion)
389
+ {
390
+ try
391
+ {
392
+ parallel_for_impl (range, body, nstripes);
393
+ flagNestedParallelFor = 0 ;
394
+ }
395
+ catch (...)
396
+ {
397
+ flagNestedParallelFor = 0 ;
398
+ throw ;
399
+ }
400
+ }
401
+ else // nested parallel_for_() calls are not parallelized
402
+ #endif // CV_PARALLEL_FRAMEWORK
403
+ {
404
+ (void )nstripes;
405
+ body (range);
406
+ }
407
+ }
380
408
381
- static int flagNestedParallelFor = 0 ;
382
- bool isNotNesterParallelFor = CV_XADD (&flagNestedParallelFor, 1 ) == 0 ;
383
- if (numThreads != 0 && isNotNesterParallelFor)
409
+ #ifdef CV_PARALLEL_FRAMEWORK
410
+ static void parallel_for_impl (const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
411
+ {
412
+ if ((numThreads < 0 || numThreads > 1 ) && range.end - range.start > 1 )
384
413
{
385
414
ParallelLoopBodyWrapperContext ctx (body, range, nstripes);
386
415
ProxyLoopBody pbody (ctx);
387
416
cv::Range stripeRange = pbody.stripeRange ();
388
417
if ( stripeRange.end - stripeRange.start == 1 )
389
418
{
390
419
body (range);
391
- flagNestedParallelFor = 0 ;
392
420
return ;
393
421
}
394
422
@@ -444,16 +472,14 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
444
472
#error You have hacked and compiling with unsupported parallel framework
445
473
446
474
#endif
447
- flagNestedParallelFor = 0 ;
448
475
}
449
476
else
450
-
451
- #endif // CV_PARALLEL_FRAMEWORK
452
477
{
453
- (void )nstripes;
454
478
body (range);
455
479
}
456
480
}
481
+ #endif // CV_PARALLEL_FRAMEWORK
482
+
457
483
458
484
int cv::getNumThreads (void )
459
485
{
0 commit comments