summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-01-22 02:16:53 +0100
committerLennart Poettering <lennart@poettering.net>2009-01-22 02:17:19 +0100
commit4dc191646750a15c7f92f945816b59cd91c5728c (patch)
tree87f8ff994c10daa1c94af1d321dfd358e35f8b07
parentc0e4e5a86828cb63d43c56db3a37d4e2c4db7a46 (diff)
add API pa_ncpus()
-rw-r--r--src/daemon/main.c2
-rw-r--r--src/pulsecore/core-util.c12
-rw-r--r--src/pulsecore/core-util.h2
3 files changed, 16 insertions, 0 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 68e64c17..f4836072 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -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
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index fcb5c421..e65b1796 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -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;
+}
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 44b3af32..18901f47 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -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