Add a method to get the system's page size
This commit is contained in:
parent
248832b266
commit
3baf9d0e81
@ -499,6 +499,7 @@ IF(HAVE_INTRIN_H)
|
|||||||
}" HAVE_CPUID_INTRINSIC)
|
}" HAVE_CPUID_INTRINSIC)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF)
|
||||||
CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
|
CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
|
||||||
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
|
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
|
||||||
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
|
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
|
||||||
|
@ -10,8 +10,20 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_WINDOWS_H
|
#ifdef HAVE_WINDOWS_H
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#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)
|
void *al_malloc(size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_ALIGNED_ALLOC)
|
#if defined(HAVE_ALIGNED_ALLOC)
|
||||||
@ -60,3 +72,39 @@ void al_free(void *ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
}
|
||||||
|
@ -14,6 +14,15 @@ void *al_malloc(size_t alignment, size_t size);
|
|||||||
void *al_calloc(size_t alignment, size_t size);
|
void *al_calloc(size_t alignment, size_t size);
|
||||||
void al_free(void *ptr);
|
void al_free(void *ptr);
|
||||||
|
|
||||||
|
size_t al_get_page_size(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns non-0 if the allocation function has direct alignment handling.
|
||||||
|
* Otherwise, the standard malloc is used with an over-allocation and pointer
|
||||||
|
* offset strategy.
|
||||||
|
*/
|
||||||
|
int al_is_sane_alignment_allocator(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
/* Define if HRTF data is embedded in the library */
|
/* Define if HRTF data is embedded in the library */
|
||||||
#cmakedefine ALSOFT_EMBED_HRTF_DATA
|
#cmakedefine ALSOFT_EMBED_HRTF_DATA
|
||||||
|
|
||||||
|
/* Define if we have the sysconf function */
|
||||||
|
#cmakedefine HAVE_SYSCONF
|
||||||
|
|
||||||
/* Define if we have the C11 aligned_alloc function */
|
/* Define if we have the C11 aligned_alloc function */
|
||||||
#cmakedefine HAVE_ALIGNED_ALLOC
|
#cmakedefine HAVE_ALIGNED_ALLOC
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user