Skip to content

Commit 900c406

Browse files
committed
core: fix threads count in pthreads
1 parent 235f2cc commit 900c406

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

modules/core/src/parallel_pthreads.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ class ThreadManager
206206
pthread_mutex_t m_manager_access_mutex;
207207

208208
static const char m_env_name[];
209-
static const unsigned int m_default_number_of_threads;
210209

211210
work_load m_work_load;
212211

@@ -223,14 +222,6 @@ class ThreadManager
223222

224223
const char ThreadManager::m_env_name[] = "OPENCV_FOR_THREADS_NUM";
225224

226-
#ifdef ANDROID
227-
// many modern phones/tables have 4-core CPUs. Let's use no more
228-
// than 2 threads by default not to overheat the devices
229-
const unsigned int ThreadManager::m_default_number_of_threads = 2;
230-
#else
231-
const unsigned int ThreadManager::m_default_number_of_threads = 8;
232-
#endif
233-
234225
ForThread::~ForThread()
235226
{
236227
if(m_state == eFTStarted)
@@ -534,7 +525,15 @@ void ThreadManager::setNumOfThreads(size_t n)
534525

535526
size_t ThreadManager::defaultNumberOfThreads()
536527
{
537-
unsigned int result = m_default_number_of_threads;
528+
#ifdef ANDROID
529+
// many modern phones/tables have 4-core CPUs. Let's use no more
530+
// than 2 threads by default not to overheat the devices
531+
const unsigned int default_number_of_threads = 2;
532+
#else
533+
const unsigned int default_number_of_threads = (unsigned int)std::max(1, cv::getNumberOfCPUs());
534+
#endif
535+
536+
unsigned int result = default_number_of_threads;
538537

539538
char * env = getenv(m_env_name);
540539

0 commit comments

Comments
 (0)