From: Mathieu Desnoyers Date: Wed, 23 Sep 2009 17:13:29 +0000 (-0400) Subject: Add offsetof to compiler.h X-Git-Tag: v0.1~46 X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=commitdiff_plain;h=3d7be7ca4e2451381a8fc8a00bd6d7dcbf3b678f Add offsetof to compiler.h Signed-off-by: Mathieu Desnoyers --- diff --git a/compiler.h b/compiler.h index 142b9a6..99972f3 100644 --- a/compiler.h +++ b/compiler.h @@ -37,4 +37,14 @@ */ #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&x) +#if (__GNUC__ == 4) +#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) +#endif + +#ifdef __compiler_offsetof +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) +#else +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + #endif /* _COMPILER_H */ diff --git a/tests/api_gcc.h b/tests/api_gcc.h index 1ad7345..963f842 100644 --- a/tests/api_gcc.h +++ b/tests/api_gcc.h @@ -282,12 +282,12 @@ cmpxchg(volatile long *ptr, long oldval, long newval) #include #include #include +#include /* #include "atomic.h" */ /* * Compiler magic. */ -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) @@ -634,7 +634,6 @@ static void smp_init(void) #define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 ((void *) 0x00200200) -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) diff --git a/tests/api_ppc.h b/tests/api_ppc.h index 8a03faa..1d9c47e 100644 --- a/tests/api_ppc.h +++ b/tests/api_ppc.h @@ -653,7 +653,6 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) /* * Compiler magic. */ -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) @@ -1005,7 +1004,6 @@ static void smp_init(void) #define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 ((void *) 0x00200200) -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) diff --git a/tests/api_x86.h b/tests/api_x86.h index f48fce9..d64eb8d 100644 --- a/tests/api_x86.h +++ b/tests/api_x86.h @@ -346,7 +346,6 @@ __asm__ __volatile__(LOCK_PREFIX "orl %0,%1" \ /* * Compiler magic. */ -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) @@ -693,7 +692,6 @@ static void smp_init(void) #define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 ((void *) 0x00200200) -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})