From 82cfd4862f2eccef35f00fb75bd687927092deb7 Mon Sep 17 00:00:00 2001 From: "mostang.com!davidm" Date: Tue, 20 Jan 2004 23:50:00 +0000 Subject: [PATCH] (cmpxchg_ptr): Use a union to do the pointer-casting so that GCC knows it can't use ANSI-C aliasing rules. (Logical change 1.155) --- include/internal.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/include/internal.h b/include/internal.h index 9b95161a..4409b5d7 100644 --- a/include/internal.h +++ b/include/internal.h @@ -140,9 +140,19 @@ do { \ #ifdef HAVE_ATOMIC_OPS_H # include -# define cmpxchg_ptr(_ptr,_o,_n) AO_compare_and_swap((AO_T *)_ptr, \ - (AO_T) (_o), \ - (AO_T) (_n)) +static inline int +cmpxchg_ptr (void *addr, void *old, void *new) +{ + union + { + void *vp; + AO_t *aop; + } + u; + + u.vp = addr; + return AO_compare_and_swap(u.aop, (AO_t) old, (AO_t) new); +} # define fetch_and_add1(_ptr) AO_fetch_and_add1(_ptr) /* GCC 3.2.0 on HP-UX crashes on cmpxchg_ptr() */ # if !(defined(__hpux) && __GNUC__ == 3 && __GNUC_MINOR__ == 2) @@ -152,9 +162,19 @@ do { \ #else # ifdef HAVE_IA64INTRIN_H # include -# define cmpxchg_ptr(_ptr,_o,_n) \ - (__sync_bool_compare_and_swap((volatile long *) (_ptr), \ - (long) (_o), (long) (_n))) +static inline int +cmpxchg_ptr (void *addr, void *old, void *new) +{ + union + { + void *vp; + long *vlp; + } + u; + + u.vp = addr; + return __sync_bool_compare_and_swap(u.vlp, (long) old, (long) new); +} # define fetch_and_add1(_ptr) __sync_fetch_and_add(_ptr, 1) # define HAVE_CMPXCHG # define HAVE_FETCH_AND_ADD1