[vlc-devel] [PATCH] vlc_GetCPUCount: add Solaris detection

Francois Cartegnie fcvlcdev at free.fr
Mon Jun 14 18:36:52 CEST 2010


---
 src/misc/cpu.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 83b9560..71aed9d 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -49,6 +49,13 @@
 #include <sys/sysctl.h>
 #endif
 
+#if defined(__SunOS)
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/processor.h>
+#include <sys/pset.h>
+#endif
+
 #if defined( __i386__ ) || defined( __x86_64__ ) || defined( __powerpc__ ) \
  || defined( __ppc__ ) || defined( __ppc64__ ) || defined( __powerpc64__ )
 # ifndef WIN32
@@ -351,6 +358,26 @@ unsigned vlc_GetCPUCount(void)
     if (sysctlbyname("hw.ncpu", &count, &size, NULL, 0))
         return 1; /* Failure */
     return count;
+#elif defined(__SunOS)
+    unsigned count = 0;
+    int type;
+    u_int numcpus;
+    processorid_t *cpulist;
+    processor_info_t cpuinfo;
+    cpulist = malloc(sizeof(processorid_t) * sysconf(_SC_NPROCESSORS_MAX));
+    if (!cpulist) return 1;
+    if (pset_info(PS_MYID, &type, &numcpus, cpulist)==0)
+    {
+        for (u_int i = 0; i < numcpus; i++)
+        {
+            if (!processor_info(cpulist[i], &cpuinfo))
+                count += (cpuinfo.pi_state == P_ONLINE)?1:0;
+        }
+    } else {
+        count = sysconf(_SC_NPROCESSORS_ONLN);
+    }
+    free(cpulist);
+    return (count>0)?count:1;
 #else
 #   warning "vlc_GetCPUCount is not implemented for your platform"
     return 1;
-- 
1.5.6.5




More information about the vlc-devel mailing list