]> git.sesse.net Git - x264/commitdiff
Re-add support for glibc <2.6, which doesn't have CPU_COUNT
authorAnton Mitrofanov <BugMaster@narod.ru>
Fri, 5 Aug 2011 11:59:20 +0000 (15:59 +0400)
committerFiona Glaser <fiona@x264.com>
Fri, 5 Aug 2011 21:42:49 +0000 (14:42 -0700)
common/cpu.c
configure

index 10988c3fffc10aeffb7389c4faa8af238cb2d721..dc7e554a2dc1588b542a1827beeb1dc1bfbd6ea4 100644 (file)
@@ -29,7 +29,7 @@
 #include "common.h"
 #include "cpu.h"
 
-#if HAVE_PTHREAD && SYS_LINUX
+#if HAVE_POSIXTHREAD && SYS_LINUX
 #include <sched.h>
 #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;
index f1a43b5165898d975b55f7723f57992b60386326..433253728923be9fd0d3f0362eb0a7c6e860c5fe 100755 (executable)
--- 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