message: core: fix build getNumberOfCPUs for JavaScript
diff: @@ -747,7 +747,7 @@ int cv::getThreadNum(void)
  }
  -#if defined __linux__ || defined __GLIBC__ || defined __EMSCRIPTEN__ || defined __HAIKU__ || defined __ANDROID__
  +#if defined __linux__ || defined __GLIBC__ || defined __HAIKU__ || defined __ANDROID__
  #define CV_CPU_GROUPS_1
  #endif
  @@ -861,6 +861,7 @@ int cv::getNumberOfCPUs(void)
  #endif
  #if defined _WIN32
  +
  SYSTEM_INFO sysinfo;
  #if (defined(_M_ARM) || defined(_M_ARM64) || defined(_M_X64) || defined(WINRT)) && _WIN32_WINNT >= 0x501
  GetNativeSystemInfo( &sysinfo );
  @@ -870,6 +871,30 @@ int cv::getNumberOfCPUs(void)
  unsigned ncpus_sysinfo = sysinfo.dwNumberOfProcessors < 0 ? 1 : sysinfo.dwNumberOfProcessors; /* Just a fail safe */
  ncpus = minNonZero(ncpus, ncpus_sysinfo);
  +#elif defined __APPLE__
  +
  + int numCPU=0;
  + int mib[4];
  + size_t len = sizeof(numCPU);
  +
  + /* set the mib for hw.ncpu */
  + mib[0] = CTL_HW;
  + mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
  +
  + /* get the number of CPUs from the system */
  + sysctl(mib, 2, &numCPU, &len, NULL, 0);
  +
  + if( numCPU < 1 )
  + {
  + mib[1] = HW_NCPU;
  + sysctl( mib, 2, &numCPU, &len, NULL, 0 );
  +
  + if( numCPU < 1 )
  + numCPU = 1;
  + }
  +
  + ncpus = minNonZero(ncpus, (unsigned)numCPU);
  +
  #elif defined CV_CPU_GROUPS_1
  #if defined CV_HAVE_CGROUPS
  @@ -883,7 +908,10 @@ int cv::getNumberOfCPUs(void)
  static unsigned ncpus_impl_devices = (unsigned)getNumberOfCPUsImpl("/sys/devices/system/cpu/online");
  ncpus = minNonZero(ncpus, ncpus_impl_devices);
  +#endif
  +
  #if defined _GNU_SOURCE \
  + && !defined(__EMSCRIPTEN__) \
  && !defined(__ANDROID__) // TODO: add check for modern Android NDK
  cpu_set_t cpu_set;
  @@ -895,32 +923,13 @@ int cv::getNumberOfCPUs(void)
  #endif
  +#if !defined(_WIN32) && !defined(__APPLE__)
  +
  static unsigned cpu_count_sysconf = (unsigned)sysconf( _SC_NPROCESSORS_ONLN );
  ncpus = minNonZero(ncpus, cpu_count_sysconf);
  -#elif defined __APPLE__
  - int numCPU=0;
  - int mib[4];
  - size_t len = sizeof(numCPU);
  -
  - /* set the mib for hw.ncpu */
  - mib[0] = CTL_HW;
  - mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
  -
  - /* get the number of CPUs from the system */
  - sysctl(mib, 2, &numCPU, &len, NULL, 0);
  -
  - if( numCPU < 1 )
  - {
  - mib[1] = HW_NCPU;
  - sysctl( mib, 2, &numCPU, &len, NULL, 0 );
  -
  - if( numCPU < 1 )
  - numCPU = 1;
  - }
  -
  - ncpus = minNonZero(ncpus, (unsigned)numCPU);
  #endif
  +
  return ncpus != 0 ? ncpus : 1;
  }
  