eina: detect page size in a portable way.

This commit is contained in:
Cedric BAIL 2013-11-10 09:25:16 +01:00
parent 35228f32f1
commit ecaca1d365
4 changed files with 57 additions and 1 deletions

View File

@ -825,7 +825,7 @@ EFL_CHECK_GCC_BUILTIN([bswap64], [HAVE_BSWAP64])
AC_CHECK_FUNCS([fchmod])
EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr])
EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr getpagesize])
enable_log="no"
if test "x${efl_func_fnmatch}" = "xyes" && test "x${want_log}" = "xyes" ; then

View File

@ -235,6 +235,20 @@ long ret = splice(0, 0, 1, 0, 400, 0);
]])
])
dnl _EFL_CHECK_FUNC_GETPAGESIZE is for internal use
dnl _EFL_CHECK_FUNC_GETPAGESIZE(EFL, VARIABLE)
AC_DEFUN([_EFL_CHECK_FUNC_GETPAGESIZE],
[EFL_FIND_LIB_FOR_CODE([$1], [], [$2], [[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
]],
[[
long sz;
sz = getpagesize();
]])
])
dnl Macro that checks function availability
dnl
dnl EFL_CHECK_FUNC(EFL, FUNCTION)

View File

@ -46,13 +46,17 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "eina_log.h"
#include "eina_cpu.h"
/*============================================================================*
* Local *
*============================================================================*/
static void _eina_page_size(void);
/* FIXME this ifdefs should be replaced */
#if defined(__i386__) || defined(__x86_64__)
/* We save ebx and restore it to be PIC compatible */
@ -140,6 +144,9 @@ eina_cpu_init(void)
#endif
// FIXME: Handle NEON and friends
// Figure out the page size for this system
_eina_page_size();
return EINA_TRUE;
}
@ -237,6 +244,40 @@ _eina_cpu_count_internal(void)
#endif
}
static int _page_size = 0;
static void
_eina_page_size(void)
{
#ifdef _WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
_page_size = (int)si.dwPageSize;
#elif defined _SC_PAGESIZE
_page_size = (int)sysconf(_SC_PAGESIZE);
#elif defined _SC_PAGE_SIZE
_page_size = (int)sysconf(_SC_PAGE_SIZE);
#elif defined HAVE_GETPAGESIZE
_page_size = getpagesize();
#else
# warn "Falling back to a safe default page size (4K) !"
_page_size = 4096;
#endif
if (_page_size < 1)
{
EINA_LOG_ERR("system reported weird value for PAGESIZE, assuming 4096.");
_page_size = 4096;
}
}
EAPI int eina_cpu_page_size(void)
{
if (_page_size == 0) _eina_page_size();
return _page_size;
}
EAPI int eina_cpu_count(void)
{
return _cpu_count;

View File

@ -40,6 +40,7 @@ EAPI extern Eina_Cpu_Features eina_cpu_features;
EAPI Eina_Cpu_Features eina_cpu_features_get(void);
EAPI int eina_cpu_count(void);
EAPI int eina_cpu_page_size(void);
static inline unsigned short eina_swap16(unsigned short x);
static inline unsigned int eina_swap32(unsigned int x);