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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user