From: Sam Hocevar Date: Tue, 12 Dec 2006 02:17:44 +0000 (+0000) Subject: * Do not assume anything about sizeof(cpu_set_t). X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=fa2c1e5430619c6011dfe2ffbebbd59557afa228;p=x264.git * Do not assume anything about sizeof(cpu_set_t). git-svn-id: svn://svn.videolan.org/x264/trunk@606 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/cpu.c b/common/cpu.c index 3e50d45c..49eee3b1 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -163,16 +163,18 @@ int x264_cpu_num_processors( void ) return 1; #elif defined(SYS_LINUX) || defined(WIN32) + unsigned int bit; int np; #if defined(WIN32) uint32_t p_aff, s_aff; GetProcessAffinityMask( GetCurrentProcess(), &p_aff, &s_aff ); #else - uint64_t p_aff; - sched_getaffinity( 0, sizeof(p_aff), (cpu_set_t*)&p_aff ); + cpu_set_t p_aff; + memset( &p_aff, 0, sizeof(p_aff) ); + sched_getaffinity( 0, sizeof(p_aff), &p_aff ); #endif - for( np = 0; p_aff != 0; p_aff >>= 1 ) - np += p_aff&1; + for( np = 0, bit = 0; bit < sizeof(p_aff); bit++ ) + np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1; return np; #elif defined(SYS_BEOS)