2 * Copyright (C) 2011-2012 Juho Vähä-Herttua
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
20 #define SYSTEM_GET_PAGESIZE(ret) do {\
25 #define SYSTEM_GET_TIME(ret) ret = timeGetTime()
27 #define ALIGNED_MALLOC(memptr, alignment, size) do {\
28 char *ptr = malloc(sizeof(void*) + (size) + (alignment)-1);\
31 size_t ptrval = (size_t)ptr + sizeof(void*) + (alignment)-1;\
32 ptrval = ptrval / (alignment) * (alignment);\
33 memptr = (void *)ptrval;\
34 *(((void **)memptr)-1) = ptr;\
37 #define ALIGNED_FREE(memptr) free(*(((void **)memptr)-1))
41 #define SYSTEM_GET_PAGESIZE(ret) ret = sysconf(_SC_PAGESIZE)
42 #define SYSTEM_GET_TIME(ret) do {\
44 gettimeofday(&tv, NULL);\
45 ret = (unsigned int)(tv.tv_sec*1000 + tv.tv_usec/1000);\
48 #define ALIGNED_MALLOC(memptr, alignment, size) if (posix_memalign((void **)&memptr, alignment, size)) memptr = NULL
49 #define ALIGNED_FREE(memptr) free(memptr)