diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-09-02 20:34:57 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-09-02 20:34:57 +0000 |
commit | fe1f55b877909a831f69497b53f2a64b952cd47d (patch) | |
tree | cd8a6411fa7fcefeab685bb69ca4a21ab5b8200d | |
parent | 1df817cb0a7dfbcb6588df1b1b08786f825b7138 (diff) |
add a couple of macros for memory page alignment
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1742 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | src/pulsecore/macro.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h index efd0f5ed..53e52fd0 100644 --- a/src/pulsecore/macro.h +++ b/src/pulsecore/macro.h @@ -25,15 +25,39 @@ ***/ #include <sys/types.h> +#include <unistd.h> #include <assert.h> +#include <limits.h> +#include <unistd.h> + #include <pulsecore/log.h> +#if defined(PAGE_SIZE) +#define PA_PAGE_SIZE ((size_t) PAGE_SIZE) +#elif defined(PAGESIZE) +#define PA_PAGE_SIZE ((size_t) PAGESIZE) +#elif defined(HAVE_SYSCONF) +#define PA_PAGE_SIZE ((size_t) (sysconf(_SC_PAGE_SIZE))) +#else +/* Let's hope it's like x86. */ +#define PA_PAGE_SIZE ((size_t) 4096) +#endif + static inline size_t pa_align(size_t l) { return (((l + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*)); } - #define PA_ALIGN(x) (pa_align(x)) +static inline void* pa_page_align_ptr(const void *p) { + return (void*) (((size_t) p) & ~(PA_PAGE_SIZE-1)); +} +#define PA_PAGE_ALIGN_PTR(x) (pa_page_align_ptr(x)) + +static inline size_t pa_page_align(size_t l) { + return l & ~(PA_PAGE_SIZE-1); +} +#define PA_PAGE_ALIGN(x) (pa_page_align(x)) + #define PA_ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0])) #define SA_MAX(a, b) ((a) > (b) ? (a) : (b)) |