aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Grunau <janne-libav@jannau.net>2011-12-24 00:27:12 +0100
committerJanne Grunau <janne-libav@jannau.net>2011-12-31 17:40:12 +0100
commitbcc73960657538f601dc90076e30df3cc6032569 (patch)
tree585406fbfd86394408eedff45b46ce488a3412f1
parent937ff3a18a637a28e56752b57b6c2f6ed47b04c1 (diff)
downloadffmpeg-bcc73960657538f601dc90076e30df3cc6032569.tar.gz
threads: add sysconf based number of CPUs detection
Can act as fallback and should work on a couple of Unix systems.
-rwxr-xr-xconfigure2
-rw-r--r--libavcodec/pthread.c7
2 files changed, 9 insertions, 0 deletions
diff --git a/configure b/configure
index 413c02fae8..b7f0acdc0a 100755
--- a/configure
+++ b/configure
@@ -1138,6 +1138,7 @@ HAVE_LIST="
symver
symver_asm_label
symver_gnu_asm
+ sysconf
sysctl
sys_mman_h
sys_param_h
@@ -2858,6 +2859,7 @@ check_func strerror_r
check_func strptime
check_func strtok_r
check_func sched_getaffinity
+check_func sysconf
check_func sysctl
check_func_headers io.h setmode
check_func_headers lzo/lzo1x.h lzo1x_999_compress
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);