Commit 1ff80a23 authored by Eric Petit's avatar Eric Petit

Nicer OS X x264_cpu_num_processors (thanks David)


git-svn-id: svn://svn.videolan.org/x264/trunk@547 df754926-b1dd-0310-bc7b-ec298dee348c
parent 3493a54d
......@@ -28,8 +28,11 @@
#ifdef SYS_BEOS
#include <kernel/OS.h>
#endif
#ifdef SYS_MACOSX
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#include <stdio.h>
#include <string.h>
#include "common.h"
......@@ -178,22 +181,13 @@ int x264_cpu_num_processors( void )
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 );
int numberOfCPUs;
size_t length = sizeof( numberOfCPUs );
if( sysctlbyname("hw.ncpu", &numberOfCPUs, &length, NULL, 0) )
{
numberOfCPUs = 1;
}
return num;
return numberOfCPUs;
#else
return 1;
......
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