add API pa_ncpus()

This commit is contained in:
Lennart Poettering 2009-01-22 02:16:53 +01:00
parent c0e4e5a868
commit 4dc1916467
3 changed files with 16 additions and 0 deletions

View file

@ -823,6 +823,8 @@ int main(int argc, char *argv[]) {
pa_log_debug(_("Running on host: %s"), s); pa_log_debug(_("Running on host: %s"), s);
pa_xfree(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); pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);
#ifdef HAVE_VALGRIND_MEMCHECK_H #ifdef HAVE_VALGRIND_MEMCHECK_H

View file

@ -2541,3 +2541,15 @@ void pa_reduce(unsigned *num, unsigned *den) {
pa_assert(pa_gcd(*num, *den) == 1); 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;
}

View file

@ -213,4 +213,6 @@ static inline pa_bool_t pa_in_valgrind(void) {
unsigned pa_gcd(unsigned a, unsigned b); unsigned pa_gcd(unsigned a, unsigned b);
void pa_reduce(unsigned *num, unsigned *den); void pa_reduce(unsigned *num, unsigned *den);
unsigned pa_ncpus(void);
#endif #endif