Merge pull request #3637 from martin-frbg/issue3636

Add fallback value for bogus sc_nprocessors_conf in getarch
This commit is contained in:
Martin Kroeker 2022-05-27 10:23:02 +02:00 committed by GitHub
commit 28a24a4d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -1693,16 +1693,19 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static int get_num_cores(void) { static int get_num_cores(void) {
int count;
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
SYSTEM_INFO sysinfo; SYSTEM_INFO sysinfo;
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
int m[2], count; int m[2];
size_t len; size_t len;
#endif #endif
#if defined(linux) || defined(__sun__) #if defined(linux) || defined(__sun__)
//returns the number of processors which are currently online //returns the number of processors which are currently online
return sysconf(_SC_NPROCESSORS_CONF); count = sysconf(_SC_NPROCESSORS_CONF);
if (count <= 0) count = 2;
return count;
#elif defined(OS_WINDOWS) #elif defined(OS_WINDOWS)
@ -1714,12 +1717,14 @@ static int get_num_cores(void) {
m[1] = HW_NCPU; m[1] = HW_NCPU;
len = sizeof(int); len = sizeof(int);
sysctl(m, 2, &count, &len, NULL, 0); sysctl(m, 2, &count, &len, NULL, 0);
if (count <= 0) count = 2;
return count; return count;
#elif defined(AIX) #elif defined(AIX)
//returns the number of processors which are currently online //returns the number of processors which are currently online
return sysconf(_SC_NPROCESSORS_ONLN); count = sysconf(_SC_NPROCESSORS_ONLN);
if (count <= 0) count = 2;
#else #else
return 2; return 2;