diff options
author | Janne Grunau <janne-libav@jannau.net> | 2011-12-24 00:27:12 +0100 |
---|---|---|
committer | Janne Grunau <janne-libav@jannau.net> | 2011-12-31 17:40:12 +0100 |
commit | bcc73960657538f601dc90076e30df3cc6032569 (patch) | |
tree | 585406fbfd86394408eedff45b46ce488a3412f1 /libavcodec | |
parent | 937ff3a18a637a28e56752b57b6c2f6ed47b04c1 (diff) | |
download | ffmpeg-bcc73960657538f601dc90076e30df3cc6032569.tar.gz |
threads: add sysconf based number of CPUs detection
Can act as fallback and should work on a couple of Unix systems.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/pthread.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 73d96fca1a..400abf4f6c 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -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); |