]> granicus.if.org Git - libx264/commitdiff
Nicer OS X x264_cpu_num_processors (thanks David)
authorEric Petit <titer@videolan.org>
Wed, 2 Aug 2006 18:11:21 +0000 (18:11 +0000)
committerEric Petit <titer@videolan.org>
Wed, 2 Aug 2006 18:11:21 +0000 (18:11 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@547 df754926-b1dd-0310-bc7b-ec298dee348c

common/cpu.c

index 7389d03c9fbfa1de2a5236fa814c5bc3c241a44e..3e50d45cec64066da13d47a1b55299f62ec2f61a 100644 (file)
 #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;