threads: add sysconf based number of CPUs detection

Can act as fallback and should work on a couple of Unix systems.
pull/3/head
Janne Grunau 13 years ago
parent 937ff3a18a
commit bcc7396065
  1. 2
      configure
  2. 7
      libavcodec/pthread.c

2
configure vendored

@ -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

@ -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);

Loading…
Cancel
Save