summaryrefslogtreecommitdiff
path: root/src/lib/eina
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 /src/lib/eina
parent35228f32f189f90975729ca2dd0f3755f0e3db03 (diff)
eina: detect page size in a portable way.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_cpu.c41
-rw-r--r--src/lib/eina/eina_cpu.h1
2 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index 670b21c5d0..82c0f047d4 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 651d925653..e31ed76735 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);