From 47f2263e0fea2f70d22b1cbef699e283d6063764 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Fri, 5 Aug 2011 15:59:20 +0400 Subject: [PATCH] Re-add support for glibc <2.6, which doesn't have CPU_COUNT --- common/cpu.c | 14 ++++++++++++-- configure | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/common/cpu.c b/common/cpu.c index 6185782d..02f4c348 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -29,7 +29,7 @@ #include "common.h" #include "cpu.h" -#if HAVE_PTHREAD && SYS_LINUX +#if HAVE_POSIXTHREAD && SYS_LINUX #include #endif #if SYS_BEOS @@ -366,7 +366,17 @@ int x264_cpu_num_processors( void ) #elif SYS_LINUX cpu_set_t p_aff; - return sched_getaffinity( 0, sizeof(p_aff), &p_aff ) ? 1 : CPU_COUNT(&p_aff); + memset( &p_aff, 0, sizeof(p_aff) ); + if( sched_getaffinity( 0, sizeof(p_aff), &p_aff ) ) + return 1; +#if HAVE_CPU_COUNT + return CPU_COUNT(&p_aff); +#else + int np = 0; + for( unsigned int bit = 0; bit < 8 * sizeof(p_aff); bit++ ) + np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1; + return np; +#endif #elif SYS_BEOS system_info info; diff --git a/configure b/configure index f1a43b51..43325372 100755 --- a/configure +++ b/configure @@ -249,7 +249,7 @@ cross_prefix="" EXE="" # list of all preprocessor HAVE values we can define -CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F VISUALIZE SWSCALE LAVF FFMS GPAC GF_MALLOC AVS GPL VECTOREXT INTERLACED" +CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F VISUALIZE SWSCALE LAVF FFMS GPAC GF_MALLOC AVS GPL VECTOREXT INTERLACED CPU_COUNT" # parse options @@ -703,6 +703,9 @@ fi if [ "$thread" = "posix" ]; then LDFLAGS="$LDFLAGS $libpthread" define HAVE_POSIXTHREAD + if [ "$SYS" = "LINUX" ] && cc_check sched.h "-D_GNU_SOURCE -Werror" "cpu_set_t p_aff; return CPU_COUNT(&p_aff);" ; then + define HAVE_CPU_COUNT + fi fi if [ "$thread" = "win32" ]; then # cygwin does not support win32 threads -- 2.47.3