Commit 3493a54d authored by Eric Petit's avatar Eric Petit

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
parent 86ec16c1
......@@ -25,7 +25,11 @@
#define _GNU_SOURCE
#include <sched.h>
#endif
#ifdef SYS_BEOS
#include <kernel/OS.h>
#endif
#include <stdio.h>
#include <string.h>
#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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment