add API pa_ncpus()
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Jan 2009 01:16:53 +0000 (02:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Jan 2009 01:17:19 +0000 (02:17 +0100)
src/daemon/main.c
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index 68e64c1..f483607 100644 (file)
@@ -823,6 +823,8 @@ int main(int argc, char *argv[]) {
     pa_log_debug(_("Running on host: %s"), s);
     pa_xfree(s);
 
+    pa_log_debug(_("Found %u CPUs."), pa_ncpus());
+
     pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
index fcb5c42..e65b179 100644 (file)
@@ -2541,3 +2541,15 @@ void pa_reduce(unsigned *num, unsigned *den) {
 
     pa_assert(pa_gcd(*num, *den) == 1);
 }
+
+unsigned pa_ncpus(void) {
+    long ncpus;
+
+#ifdef _SC_NPROCESSORS_CONF
+    ncpus = sysconf(_SC_NPROCESSORS_CONF);
+#else
+    ncpus = 1;
+#endif
+
+    return ncpus <= 0 ? 1 : (unsigned) ncpus;
+}
index 44b3af3..18901f4 100644 (file)
@@ -213,4 +213,6 @@ static inline pa_bool_t pa_in_valgrind(void) {
 unsigned pa_gcd(unsigned a, unsigned b);
 void pa_reduce(unsigned *num, unsigned *den);
 
+unsigned pa_ncpus(void);
+
 #endif