aboutsummaryrefslogtreecommitdiffstats
path: root/common/almalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/almalloc.c')
-rw-r--r--common/almalloc.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/almalloc.c b/common/almalloc.c
index 8c1c5794..0d982ca1 100644
--- a/common/almalloc.c
+++ b/common/almalloc.c
@@ -10,8 +10,20 @@
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+
+#ifdef __GNUC__
+#define LIKELY(x) __builtin_expect(!!(x), !0)
+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
+#else
+#define LIKELY(x) (!!(x))
+#define UNLIKELY(x) (!!(x))
#endif
+
void *al_malloc(size_t alignment, size_t size)
{
#if defined(HAVE_ALIGNED_ALLOC)
@@ -60,3 +72,39 @@ void al_free(void *ptr)
}
#endif
}
+
+size_t al_get_page_size(void)
+{
+ static size_t psize = 0;
+ if(UNLIKELY(!psize))
+ {
+#ifdef HAVE_SYSCONF
+#if defined(_SC_PAGESIZE)
+ if(!psize) psize = sysconf(_SC_PAGESIZE);
+#elif defined(_SC_PAGE_SIZE)
+ if(!psize) psize = sysconf(_SC_PAGE_SIZE);
+#endif
+#endif /* HAVE_SYSCONF */
+#ifdef _WIN32
+ if(!psize)
+ {
+ SYSTEM_INFO sysinfo;
+ memset(&sysinfo, 0, sizeof(sysinfo));
+
+ GetSystemInfo(&sysinfo);
+ psize = sysinfo.dwPageSize;
+ }
+#endif
+ if(!psize) psize = DEF_ALIGN;
+ }
+ return psize;
+}
+
+int al_is_sane_alignment_allocator(void)
+{
+#if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)
+ return 1;
+#else
+ return 0;
+#endif
+}