diff options
author | Yunqing Wang <yunqingwang@google.com> | 2011-05-05 04:59:54 -0700 |
---|---|---|
committer | Code Review <code-review@webmproject.org> | 2011-05-05 04:59:54 -0700 |
commit | aeb86d615c87d80cfd4127c915812e1299f80a33 (patch) | |
tree | c37bb2e465b6a93568a5c3c7689fbdd586e3d13d /vp8/common/generic | |
parent | 3fbade23a2c6eb060f7c65df210bc84f1a801165 (diff) | |
parent | 297b27655eaf4a0cfd097b2ae94add4b19fed9eb (diff) | |
download | libvpx-aeb86d615c87d80cfd4127c915812e1299f80a33.tar libvpx-aeb86d615c87d80cfd4127c915812e1299f80a33.tar.gz libvpx-aeb86d615c87d80cfd4127c915812e1299f80a33.tar.bz2 libvpx-aeb86d615c87d80cfd4127c915812e1299f80a33.zip |
Merge "Runtime detection of available processor cores."
Diffstat (limited to 'vp8/common/generic')
-rw-r--r-- | vp8/common/generic/systemdependent.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vp8/common/generic/systemdependent.c b/vp8/common/generic/systemdependent.c index c36ae2119..d981f3496 100644 --- a/vp8/common/generic/systemdependent.c +++ b/vp8/common/generic/systemdependent.c @@ -17,9 +17,54 @@ #include "vp8/common/idct.h" #include "vp8/common/onyxc_int.h" +#if CONFIG_MULTITHREAD +#if HAVE_UNISTD_H +#include <unistd.h> +#elif defined(_WIN32) +#include <windows.h> +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); +#endif +#endif + extern void vp8_arch_x86_common_init(VP8_COMMON *ctx); extern void vp8_arch_arm_common_init(VP8_COMMON *ctx); +#if CONFIG_MULTITHREAD +static int get_cpu_count() +{ + int core_count = 16; + +#if HAVE_UNISTD_H +#if defined(_SC_NPROCESSORS_ONLN) + core_count = sysconf(_SC_NPROCESSORS_ONLN); +#elif defined(_SC_NPROC_ONLN) + core_count = sysconf(_SC_NPROC_ONLN); +#endif +#elif defined(_WIN32) + { + PGNSI pGNSI; + SYSTEM_INFO sysinfo; + + /* Call GetNativeSystemInfo if supported or + * GetSystemInfo otherwise. */ + + pGNSI = (PGNSI) GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); + if (pGNSI != NULL) + pGNSI(&sysinfo); + else + GetSystemInfo(&sysinfo); + + core_count = sysinfo.dwNumberOfProcessors; + } +#else + /* other platforms */ +#endif + + return core_count > 0 ? core_count : 1; +} +#endif + void vp8_machine_specific_config(VP8_COMMON *ctx) { #if CONFIG_RUNTIME_CPU_DETECT @@ -88,4 +133,7 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) vp8_arch_arm_common_init(ctx); #endif +#if CONFIG_MULTITHREAD + ctx->processor_core_count = get_cpu_count(); +#endif /* CONFIG_MULTITHREAD */ } |