]> git.sesse.net Git - vlc/commitdiff
thread: Simplify vlc_GetCPUCount / add FreeBSD/NetBSD support
authorBrad Smith <brad@comstyle.com>
Sat, 28 Jan 2012 22:05:37 +0000 (17:05 -0500)
committerRafaël Carré <funman@videolan.org>
Sun, 29 Jan 2012 01:20:04 +0000 (20:20 -0500)
Looking at the current vlc_GetCPUCount() function this can be simplified.
The sysconf(4) variable _SC_NPROCESSORS_CONF is available for OS X and OpenBSD.
The change as is also adds FreeBSD and NetBSD support to vlc_GetCPUCount().

Signed-off-by: Rafaël Carré <funman@videolan.org>
src/posix/thread.c

index 001240b0eae69e2e28e0dedf10514cd2cd79c738..a7a4873076e47c10961c95630d3a81d42579ff1b 100644 (file)
 
 #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"