From 4dc191646750a15c7f92f945816b59cd91c5728c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Jan 2009 02:16:53 +0100 Subject: add API pa_ncpus() --- src/daemon/main.c | 2 ++ src/pulsecore/core-util.c | 12 ++++++++++++ src/pulsecore/core-util.h | 2 ++ 3 files changed, 16 insertions(+) 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 -- cgit