fix support for pthreads parallel_for

This commit is contained in:
Alexander Alekhin
2015-06-11 16:53:07 +03:00
parent 1f983ec39c
commit a482dcce46
6 changed files with 47 additions and 25 deletions

View File

@@ -80,6 +80,7 @@
4. HAVE_GCD - system wide, used automatically (APPLE only)
5. WINRT - system wide, used automatically (Windows RT only)
6. HAVE_CONCURRENCY - part of runtime, used automatically (Windows only - MSVS 10, MSVS 11)
7. HAVE_PTHREADS_PF - pthreads if available
*/
#if defined HAVE_TBB
@@ -125,14 +126,14 @@
# define CV_PARALLEL_FRAMEWORK "winrt-concurrency"
#elif defined HAVE_CONCURRENCY
# define CV_PARALLEL_FRAMEWORK "ms-concurrency"
#elif defined HAVE_PTHREADS
#elif defined HAVE_PTHREADS_PF
# define CV_PARALLEL_FRAMEWORK "pthreads"
#endif
namespace cv
{
ParallelLoopBody::~ParallelLoopBody() {}
#if defined HAVE_PTHREADS && HAVE_PTHREADS
#ifdef HAVE_PTHREADS_PF
void parallel_for_pthreads(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes);
size_t parallel_pthreads_get_threads_num();
void parallel_pthreads_set_threads_num(int num);
@@ -306,7 +307,7 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
Concurrency::CurrentScheduler::Detach();
}
#elif defined HAVE_PTHREADS
#elif defined HAVE_PTHREADS_PF
parallel_for_pthreads(range, body, nstripes);
@@ -365,7 +366,7 @@ int cv::getNumThreads(void)
? Concurrency::CurrentScheduler::Get()->GetNumberOfVirtualProcessors()
: pplScheduler->GetNumberOfVirtualProcessors());
#elif defined HAVE_PTHREADS
#elif defined HAVE_PTHREADS_PF
return parallel_pthreads_get_threads_num();
@@ -426,7 +427,7 @@ void cv::setNumThreads( int threads )
Concurrency::MaxConcurrency, threads-1));
}
#elif defined HAVE_PTHREADS
#elif defined HAVE_PTHREADS_PF
parallel_pthreads_set_threads_num(threads);
@@ -452,6 +453,8 @@ int cv::getThreadNum(void)
return 0;
#elif defined HAVE_CONCURRENCY
return std::max(0, (int)Concurrency::Context::VirtualProcessorId()); // zero for master thread, unique number for others but not necessary 1,2,3,...
#elif defined HAVE_PTHREADS_PF
return (int)(size_t)(void*)pthread_self(); // no zero-based indexing
#else
return 0;
#endif

View File

@@ -42,7 +42,7 @@
#include "precomp.hpp"
#if defined HAVE_PTHREADS && HAVE_PTHREADS
#ifdef HAVE_PTHREADS_PF
#include <algorithm>
#include <pthread.h>

View File

@@ -292,12 +292,6 @@ TLSData<CoreTLSData>& getCoreTlsData();
#define CL_RUNTIME_EXPORT
#endif
#ifndef HAVE_PTHREADS
#if !(defined WIN32 || defined _WIN32 || defined WINCE || defined HAVE_WINRT)
#define HAVE_PTHREADS 1
#endif
#endif
extern bool __termination; // skip some cleanups, because process is terminating
// (for example, if ExitProcess() was already called)