From 3493a54ddfd504fdd993c98a321916f98b96b09d Mon Sep 17 00:00:00 2001 From: Eric Petit Date: Tue, 1 Aug 2006 15:20:35 +0000 Subject: [PATCH] Support OS X and BeOS in x264_cpu_num_processors git-svn-id: svn://svn.videolan.org/x264/trunk@546 df754926-b1dd-0310-bc7b-ec298dee348c --- common/cpu.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/common/cpu.c b/common/cpu.c index f4585d0c..7389d03c 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -25,7 +25,11 @@ #define _GNU_SOURCE #include #endif +#ifdef SYS_BEOS +#include +#endif +#include #include #include "common.h" @@ -149,10 +153,13 @@ void x264_cpu_restore( uint32_t cpu ) #endif -#if defined(HAVE_PTHREAD) && ( defined(SYS_LINUX) || defined(WIN32) ) int x264_cpu_num_processors( void ) { +#if !defined(HAVE_PTHREAD) + return 1; + +#elif defined(SYS_LINUX) || defined(WIN32) int np; #if defined(WIN32) uint32_t p_aff, s_aff; @@ -164,13 +171,31 @@ int x264_cpu_num_processors( void ) for( np = 0; p_aff != 0; p_aff >>= 1 ) np += p_aff&1; return np; -} -#else +#elif defined(SYS_BEOS) + system_info info; + get_system_info( &info ); + return info.cpu_count; + +#elif defined(SYS_MACOSX) + FILE * pipe; + char buffer[16]; + int num = 1; + if( ( pipe = popen( "/usr/sbin/sysctl hw.ncpu", "r" ) ) ) + { + memset( buffer, 0, 16 ); + if( fgets( buffer, 16, pipe ) ) + { + if( sscanf( buffer, "hw.ncpu: %d", &num ) != 1 ) + { + num = 1; + } + } + fclose( pipe ); + } + return num; -int x264_cpu_num_processors( void ) -{ +#else return 1; -} - #endif +} -- 2.40.0