#define _GNU_SOURCE
#include <sched.h>
#endif
+#ifdef SYS_BEOS
+#include <kernel/OS.h>
+#endif
+#include <stdio.h>
#include <string.h>
#include "common.h"
#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;
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
+}