[vlc-commits] commit: Added vlc_GetCPUCount() to retreive the number of available CPU. ( Laurent Aimar )
git at videolan.org
git at videolan.org
Mon May 3 23:11:10 CEST 2010
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Mon May 3 21:54:28 2010 +0200| [933d6755d4cd316745feb90601451e4f07ee2340] | committer: Laurent Aimar
Added vlc_GetCPUCount() to retreive the number of available CPU.
It is implemented for win32 and when sched_getaffinity() is available.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=933d6755d4cd316745feb90601451e4f07ee2340
---
configure.ac | 2 +-
include/vlc_cpu.h | 1 +
src/libvlccore.sym | 1 +
src/misc/cpu.c | 32 ++++++++++++++++++++++++++++++++
4 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index 8510e84..8571ab6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -556,7 +556,7 @@ AC_CHECK_FUNCS(fdatasync,,
])
dnl Check for non-standard system calls
-AC_CHECK_FUNCS([accept4 dup3 eventfd fstatfs vmsplice])
+AC_CHECK_FUNCS([accept4 dup3 eventfd fstatfs vmsplice sched_getaffinity])
AH_BOTTOM([#include <vlc_fixups.h>])
diff --git a/include/vlc_cpu.h b/include/vlc_cpu.h
index feb6e5e..bbc7b5b 100644
--- a/include/vlc_cpu.h
+++ b/include/vlc_cpu.h
@@ -63,6 +63,7 @@
# endif
VLC_EXPORT( unsigned, vlc_CPU, ( void ) );
+VLC_EXPORT( unsigned, vlc_GetCPUCount, ( void ) );
/** Are floating point operations fast?
* If this bit is not set, you should try to use fixed-point instead.
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a8479eb..f2343e9 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -493,6 +493,7 @@ vlc_sem_destroy
vlc_sem_post
vlc_sem_wait
vlc_control_cancel
+vlc_GetCPUCount
vlc_CPU
vlc_error
vlc_event_attach
diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 3b0d278..fb705a2 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -319,6 +319,38 @@ const struct
};
/**
+ * Return the number of available logical CPU.
+ */
+unsigned vlc_GetCPUCount(void)
+{
+#ifdef WIN32
+ DWORD process_mask;
+ DWORD system_mask;
+ if (!GetProcessAffinityMask(GetCurrentProcess(), &process_mask, &system_mask))
+ return 1;
+
+ unsigned count = 0;
+ while (system_mask) {
+ count++;
+ system_mask >>= 1;
+ }
+ return count;
+#elif HAVE_SCHED_GETAFFINITY
+ cpu_set_t cpu;
+ CPU_ZERO(&cpu);
+ if (sched_getaffinity(0, sizeof(cpu), &cpu) < 0)
+ return 1;
+ unsigned count = 0;
+ for (unsigned i = 0; i < CPU_SETSIZE; i++)
+ count += CPU_ISSET(i, &cpu) != 0;
+ return count;
+#else
+# warning "vlc_GetCPUCount is not implemented for your platform"
+ return 1;
+#endif
+}
+
+/**
* Check if a directory name contains usable plugins w.r.t. the hardware
* capabilities. Loading a plugin when the hardware has insufficient
* capabilities may lead to illegal instructions (SIGILL) and must be avoided.
More information about the vlc-commits
mailing list