instead of calling sysconf() directly, add function pa_page_size() which uses the guestimate 4096 in case sysconf(_SC_PAGE_SIZE) fails using PA_ONCE to only evaluate sysconf() once the name macro.h/.c is a bit unfortunate when adding functions CID 1137925, CID 1137926, CID 1138485 --- src/Makefile.am | 2 +- src/pulsecore/macro.c | 39 +++++++++++++++++++++++++++++++++++++++ src/pulsecore/macro.h | 3 ++- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/pulsecore/macro.c diff --git a/src/Makefile.am b/src/Makefile.am index 7b19497..13c5375 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -692,7 +692,7 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \ pulsecore/lock-autospawn.c pulsecore/lock-autospawn.h \ pulsecore/log.c pulsecore/log.h \ pulsecore/ratelimit.c pulsecore/ratelimit.h \ - pulsecore/macro.h \ + pulsecore/macro.c pulsecore/macro.h \ pulsecore/mcalign.c pulsecore/mcalign.h \ pulsecore/memblock.c pulsecore/memblock.h \ pulsecore/memblockq.c pulsecore/memblockq.h \ diff --git a/src/pulsecore/macro.c b/src/pulsecore/macro.c new file mode 100644 index 0000000..70cadf1 --- /dev/null +++ b/src/pulsecore/macro.c @@ -0,0 +1,39 @@ +/*** + This file is part of PulseAudio. + + Copyright 2016 Peter Meerwald-Stadler + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <pulsecore/once.h> +#include "macro.h" + +#if defined(HAVE_SYSCONF) +size_t pa_page_size(void) { + static size_t page_size = 4096; /* Let's hope it's like x86. */ + + PA_ONCE_BEGIN { + long ret = sysconf(_SC_PAGE_SIZE); + if (ret > 0) + page_size = ret; + } PA_ONCE_END; + + return page_size; +} +#endif diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h index f80b43c..3871180 100644 --- a/src/pulsecore/macro.h +++ b/src/pulsecore/macro.h @@ -49,7 +49,8 @@ #elif defined(PAGESIZE) #define PA_PAGE_SIZE ((size_t) PAGESIZE) #elif defined(HAVE_SYSCONF) -#define PA_PAGE_SIZE ((size_t) (sysconf(_SC_PAGE_SIZE))) +size_t pa_page_size(void); +#define PA_PAGE_SIZE (pa_page_size()) #else /* Let's hope it's like x86. */ #define PA_PAGE_SIZE ((size_t) 4096) -- 2.7.4