[vlc-devel] [PATCH] thread: Simplify vlc_GetCPUCount / add FreeBSD/NetBSD support

Brad brad at comstyle.com
Sat Jan 28 23:05:37 CET 2012


Looking at the current vlc_GetCPUCount() function this can be simplified. The
sysconf(3) variable is available for OS X and OpenBSD. The change as is also
adds FreeBSD and NetBSD support to vlc_GetCPUCount().


diff --git a/src/posix/thread.c b/src/posix/thread.c
index 001240b..a7a4873 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -53,13 +53,6 @@
 
 #ifdef __APPLE__
 # include <mach/mach_init.h> /* mach_task_self in semaphores */
-# include <sys/sysctl.h>
-#endif
-
-#if defined(__OpenBSD__)
-# include <sys/param.h>
-# include <sys/sysctl.h>
-# include <machine/cpu.h>
 #endif
 
 #if defined(__SunOS)
@@ -1167,23 +1160,6 @@ unsigned vlc_GetCPUCount(void)
 
     return CPU_COUNT (&cpu);
 
-#elif defined(__APPLE__)
-    int count;
-    size_t size = sizeof(count) ;
-
-    if (sysctlbyname ("hw.ncpu", &count, &size, NULL, 0))
-        return 1; /* Failure */
-    return count;
-
-#elif defined(__OpenBSD__)
-    int selectors[2] = { CTL_HW, HW_NCPU };
-    int count;
-    size_t size = sizeof(count);
-
-    if (sysctl (selectors, 2, &count, &size, NULL, 0))
-        return 1; /* Failure */
-    return count;
-
 #elif defined(__SunOS)
     unsigned count = 0;
     int type;
@@ -1204,7 +1180,7 @@ unsigned vlc_GetCPUCount(void)
         count = sysconf (_SC_NPROCESSORS_ONLN);
     free (cpulist);
     return count ? count : 1;
-#elif defined(__ANDROID__)
+#elif defined(_SC_NPROCESSORS_CONF)
     return sysconf(_SC_NPROCESSORS_CONF);
 #else
 #   warning "vlc_GetCPUCount is not implemented for your platform"

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the vlc-devel mailing list