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

Brad git at videolan.org
Sun Jan 29 02:17:48 CET 2012


vlc | branch: master | Brad <brad at comstyle.com> | Sat Jan 28 17:05:37 2012 -0500| [89ec519cf5460f867d6c900ea4098b629bb79190] | committer: Rafaël Carré

thread: Simplify vlc_GetCPUCount / add FreeBSD/NetBSD support

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 at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=89ec519cf5460f867d6c900ea4098b629bb79190
---

 src/posix/thread.c |   26 +-------------------------
 1 files changed, 1 insertions(+), 25 deletions(-)

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"



More information about the vlc-commits mailing list