[x264-devel] Linux x264_cpu_num_processors(): use glibc macros

Rafaël Carré git at videolan.org
Sat Jul 23 02:38:52 CEST 2011


x264 | branch: master | Rafaël Carré <rafael.carre at gmail.com> | Thu Jul 14 18:51:43 2011 -0700| [44c881766e9fcba80035e8a127bbee851cdb8584] | committer: Jason Garrett-Glaser

Linux x264_cpu_num_processors(): use glibc macros
The cpu_set_t structure is considered opaque.
Also handle sched_getaffinity() error case if "cpusetsize is smaller than the size of the affinity mask used by the kernel."

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

 common/cpu.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/common/cpu.c b/common/cpu.c
index 2d43e85..6185782 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -365,14 +365,8 @@ int x264_cpu_num_processors( void )
     return sysconf( _SC_NPROCESSORS_ONLN );
 
 #elif SYS_LINUX
-    unsigned int bit;
-    int np;
     cpu_set_t p_aff;
-    memset( &p_aff, 0, sizeof(p_aff) );
-    sched_getaffinity( 0, sizeof(p_aff), &p_aff );
-    for( np = 0, bit = 0; bit < sizeof(p_aff); bit++ )
-        np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1;
-    return np;
+    return sched_getaffinity( 0, sizeof(p_aff), &p_aff ) ? 1 : CPU_COUNT(&p_aff);
 
 #elif SYS_BEOS
     system_info info;



More information about the x264-devel mailing list