aboutsummaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer2013-05-24 13:13:03 +0200
committerMichael Niedermayer2013-05-24 13:24:28 +0200
commitfe40a9f98f599699b0989d8c8cb35cb24eb2e52f (patch)
treef4ee45ae1a0762edc121ea98ce03d39557424fc7 /libavutil
parenta4d3757b29b5e9affd97cbc4e6fc2d202378610b (diff)
parent2a6eaeaa85d17b27ee0dd449183ec197c35c9675 (diff)
Merge commit '2a6eaeaa85d17b27ee0dd449183ec197c35c9675'
* commit '2a6eaeaa85d17b27ee0dd449183ec197c35c9675': Move get_logical_cpus() from lavc/pthread to lavu/cpu. Conflicts: doc/APIchanges libavcodec/pthread.c libavutil/cpu.c libavutil/cpu.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/cpu.c55
-rw-r--r--libavutil/cpu.h5
-rw-r--r--libavutil/version.h2
3 files changed, 61 insertions, 1 deletions
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index a1d1547033..0560ddbaf4 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -20,6 +20,27 @@
#include "config.h"
#include "opt.h"
+#if HAVE_SCHED_GETAFFINITY
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#include <sched.h>
+#endif
+#if HAVE_GETPROCESSAFFINITYMASK
+#include <windows.h>
+#endif
+#if HAVE_SYSCTL
+#if HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+#if HAVE_SYSCONF
+#include <unistd.h>
+#endif
+
static int flags, checked;
void av_force_cpu_flags(int arg){
@@ -173,6 +194,40 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
}
+
+int av_cpu_count(void)
+{
+ int ret, nb_cpus = 1;
+#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
+ cpu_set_t cpuset;
+
+ CPU_ZERO(&cpuset);
+
+ ret = sched_getaffinity(0, sizeof(cpuset), &cpuset);
+ if (!ret) {
+ nb_cpus = CPU_COUNT(&cpuset);
+ }
+#elif HAVE_GETPROCESSAFFINITYMASK
+ DWORD_PTR proc_aff, sys_aff;
+ ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff);
+ if (ret)
+ nb_cpus = av_popcount64(proc_aff);
+#elif HAVE_SYSCTL && defined(HW_NCPU)
+ int mib[2] = { CTL_HW, HW_NCPU };
+ size_t len = sizeof(nb_cpus);
+
+ 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
+
+ return nb_cpus;
+}
+
#ifdef TEST
#include <stdio.h>
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index c8f34e0272..df8ef8728a 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -100,6 +100,11 @@ int av_parse_cpu_flags(const char *s);
*/
int av_parse_cpu_caps(unsigned *flags, const char *s);
+/**
+ * @return the number of logical CPU cores present.
+ */
+int av_cpu_count(void);
+
/* The following CPU-specific functions shall not be called directly. */
int ff_get_cpu_flags_arm(void);
int ff_get_cpu_flags_ppc(void);
diff --git a/libavutil/version.h b/libavutil/version.h
index a88247b714..e234296b41 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 33
+#define LIBAVUTIL_VERSION_MINOR 34
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \