cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=ecaca1d365b998b3e339b387897c0646b2b3556f

commit ecaca1d365b998b3e339b387897c0646b2b3556f
Author: Cedric BAIL <[email protected]>
Date:   Sun Nov 10 09:25:16 2013 +0100

    eina: detect page size in a portable way.
---
 configure.ac            |  2 +-
 m4/efl_check_funcs.m4   | 14 ++++++++++++++
 src/lib/eina/eina_cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++
 src/lib/eina/eina_cpu.h |  1 +
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 6e32846..7671dcc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/m4/efl_check_funcs.m4 b/m4/efl_check_funcs.m4
index b976caa..9edbf08 100644
--- a/m4/efl_check_funcs.m4
+++ b/m4/efl_check_funcs.m4
@@ -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)
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index 670b21c..82c0f04 100644
--- a/src/lib/eina/eina_cpu.c
+++ b/src/lib/eina/eina_cpu.c
@@ -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;
diff --git a/src/lib/eina/eina_cpu.h b/src/lib/eina/eina_cpu.h
index 651d925..e31ed76 100644
--- a/src/lib/eina/eina_cpu.h
+++ b/src/lib/eina/eina_cpu.h
@@ -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);

-- 


Reply via email to