summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@efl.so>2013-11-10 09:25:16 +0100
committerCedric BAIL <cedric@efl.so>2013-11-10 09:25:16 +0100
commitecaca1d365b998b3e339b387897c0646b2b3556f (patch)
tree83867cd16388a17448756507cf93ca9d4be54eac
parent35228f32f189f90975729ca2dd0f3755f0e3db03 (diff)
eina: detect page size in a portable way.
-rw-r--r--configure.ac2
-rw-r--r--m4/efl_check_funcs.m414
-rw-r--r--src/lib/eina/eina_cpu.c41
-rw-r--r--src/lib/eina/eina_cpu.h1
4 files changed, 57 insertions, 1 deletions
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])
825 825
826AC_CHECK_FUNCS([fchmod]) 826AC_CHECK_FUNCS([fchmod])
827 827
828EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr]) 828EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr getpagesize])
829 829
830enable_log="no" 830enable_log="no"
831if test "x${efl_func_fnmatch}" = "xyes" && test "x${want_log}" = "xyes" ; then 831if 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);
235]]) 235]])
236]) 236])
237 237
238dnl _EFL_CHECK_FUNC_GETPAGESIZE is for internal use
239dnl _EFL_CHECK_FUNC_GETPAGESIZE(EFL, VARIABLE)
240AC_DEFUN([_EFL_CHECK_FUNC_GETPAGESIZE],
241[EFL_FIND_LIB_FOR_CODE([$1], [], [$2], [[
242#ifdef HAVE_UNISTD_H
243# include <unistd.h>
244#endif
245]],
246[[
247long sz;
248sz = getpagesize();
249]])
250])
251
238dnl Macro that checks function availability 252dnl Macro that checks function availability
239dnl 253dnl
240dnl EFL_CHECK_FUNC(EFL, FUNCTION) 254dnl 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 @@
46#include <stdio.h> 46#include <stdio.h>
47#include <string.h> 47#include <string.h>
48#include <errno.h> 48#include <errno.h>
49#include <unistd.h>
49 50
51#include "eina_log.h"
50#include "eina_cpu.h" 52#include "eina_cpu.h"
51 53
52/*============================================================================* 54/*============================================================================*
53* Local * 55* Local *
54*============================================================================*/ 56*============================================================================*/
55 57
58static void _eina_page_size(void);
59
56/* FIXME this ifdefs should be replaced */ 60/* FIXME this ifdefs should be replaced */
57#if defined(__i386__) || defined(__x86_64__) 61#if defined(__i386__) || defined(__x86_64__)
58/* We save ebx and restore it to be PIC compatible */ 62/* We save ebx and restore it to be PIC compatible */
@@ -140,6 +144,9 @@ eina_cpu_init(void)
140#endif 144#endif
141 // FIXME: Handle NEON and friends 145 // FIXME: Handle NEON and friends
142 146
147 // Figure out the page size for this system
148 _eina_page_size();
149
143 return EINA_TRUE; 150 return EINA_TRUE;
144} 151}
145 152
@@ -237,6 +244,40 @@ _eina_cpu_count_internal(void)
237#endif 244#endif
238} 245}
239 246
247static int _page_size = 0;
248
249static void
250_eina_page_size(void)
251{
252#ifdef _WIN32
253 SYSTEM_INFO si;
254
255 GetSystemInfo(&si);
256
257 _page_size = (int)si.dwPageSize;
258#elif defined _SC_PAGESIZE
259 _page_size = (int)sysconf(_SC_PAGESIZE);
260#elif defined _SC_PAGE_SIZE
261 _page_size = (int)sysconf(_SC_PAGE_SIZE);
262#elif defined HAVE_GETPAGESIZE
263 _page_size = getpagesize();
264#else
265# warn "Falling back to a safe default page size (4K) !"
266 _page_size = 4096;
267#endif
268 if (_page_size < 1)
269 {
270 EINA_LOG_ERR("system reported weird value for PAGESIZE, assuming 4096.");
271 _page_size = 4096;
272 }
273}
274
275EAPI int eina_cpu_page_size(void)
276{
277 if (_page_size == 0) _eina_page_size();
278 return _page_size;
279}
280
240EAPI int eina_cpu_count(void) 281EAPI int eina_cpu_count(void)
241{ 282{
242 return _cpu_count; 283 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;
40 40
41EAPI Eina_Cpu_Features eina_cpu_features_get(void); 41EAPI Eina_Cpu_Features eina_cpu_features_get(void);
42EAPI int eina_cpu_count(void); 42EAPI int eina_cpu_count(void);
43EAPI int eina_cpu_page_size(void);
43 44
44static inline unsigned short eina_swap16(unsigned short x); 45static inline unsigned short eina_swap16(unsigned short x);
45static inline unsigned int eina_swap32(unsigned int x); 46static inline unsigned int eina_swap32(unsigned int x);