]> granicus.if.org Git - libx264/commitdiff
Support OS X and BeOS in x264_cpu_num_processors
authorEric Petit <titer@videolan.org>
Tue, 1 Aug 2006 15:20:35 +0000 (15:20 +0000)
committerEric Petit <titer@videolan.org>
Tue, 1 Aug 2006 15:20:35 +0000 (15:20 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@546 df754926-b1dd-0310-bc7b-ec298dee348c

common/cpu.c

index f4585d0c0e7745d135797622fac70661c95cce1e..7389d03c9fbfa1de2a5236fa814c5bc3c241a44e 100644 (file)
 #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
+}