threads: add sysconf based number of CPUs detection

Can act as fallback and should work on a couple of Unix systems.
This commit is contained in:
Janne Grunau
2011-12-24 00:27:12 +01:00
parent 937ff3a18a
commit bcc7396065
2 changed files with 9 additions and 0 deletions

View File

@@ -45,6 +45,9 @@
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#if HAVE_SYSCONF
#include <unistd.h>
#endif
#include "avcodec.h"
#include "internal.h"
@@ -177,6 +180,10 @@ static int get_logical_cpus(AVCodecContext *avctx)
ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0);
if (ret == -1)
nb_cpus = 0;
#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
nb_cpus = sysconf(_SC_NPROC_ONLN);
#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
#endif
av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
return FFMIN(nb_cpus, MAX_AUTO_THREADS);