Fix QThread::idealThreadCount on Unix if sysconf or sysctl fails

The BSD4 code (including OS X) calls sysctl and if that fails, it sets
cores to -1. Similarly, the generic Unix code calls sysconf() and
assigns the returned value to cores, but sysconf can return -1 on
failure.

Change-Id: I9e521d366e9c42f36c2ba20a37e7a74539ddb8f4
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Thiago Macieira 2014-12-16 16:22:10 -08:00
parent 1c1cce67fa
commit 80d0075588

View File

@ -450,7 +450,8 @@ int QThread::idealThreadCount() Q_DECL_NOTHROW
// the rest: Linux, Solaris, AIX, Tru64 // the rest: Linux, Solaris, AIX, Tru64
cores = (int)sysconf(_SC_NPROCESSORS_ONLN); cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
#endif #endif
if (cores == -1)
return 1;
return cores; return cores;
} }