[x264-devel] Re-add support for glibc <2.6, which doesn't have CPU_COUNT

Anton Mitrofanov git at videolan.org
Wed Aug 10 05:15:11 CEST 2011


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Fri Aug  5 15:59:20 2011 +0400| [47f2263e0fea2f70d22b1cbef699e283d6063764] | committer: Jason Garrett-Glaser

Re-add support for glibc <2.6, which doesn't have CPU_COUNT

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=47f2263e0fea2f70d22b1cbef699e283d6063764
---

 common/cpu.c |   14 ++++++++++++--
 configure    |    5 ++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/common/cpu.c b/common/cpu.c
index 6185782..02f4c34 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 <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;
diff --git a/configure b/configure
index f1a43b5..4332537 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



More information about the x264-devel mailing list