From 4e1cc10bb6763bb034acab3e12b6dce0d5570386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 27 Jan 2013 01:28:04 +0100 Subject: factorise cas.h --- cas.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/cas.h b/cas.h index b2e6328..51312d1 100644 --- a/cas.h +++ b/cas.h @@ -36,36 +36,31 @@ extern "C" { #if defined(__i386__) && defined(__GNUC__) -struct _cas_pointer_t -{ - uint32_t lo; - uint32_t hi; -} __attribute__ (( __aligned__( 8 ) )); - -#define _hi(p,v) ((p).hi=(uint32_t)(v)) -#define _lo(p,v) ((p).lo=(uint32_t)(v)) -#define _hi_eq(p,v) ((p).hi==(uint32_t)(v)) -#define _lo_eq(p,v) ((p).lo==(uint32_t)(v)) +#define _cas_field_t uint32_t +#define _cas_aligned 8 #elif defined(__x86_64__) && defined(__GNUC__) -struct _cas_pointer_t -{ - uint64_t lo; - uint64_t hi; -} __attribute__ (( __aligned__( 16 ) )); - -#define _hi(p,v) ((p).hi=(uint64_t)(v)) -#define _lo(p,v) ((p).lo=(uint64_t)(v)) -#define _hi_eq(p,v) ((p).hi==(uint64_t)(v)) -#define _lo_eq(p,v) ((p).lo==(uint64_t)(v)) +#define _cas_field_t uint64_t +#define _cas_aligned 16 #else #error "cas not implemented yet for your arch" #endif +struct _cas_pointer_t +{ + _cas_field_t lo; + _cas_field_t hi; +} __attribute__ (( __aligned__( _cas_aligned ) )); + typedef struct _cas_pointer_t cas_pointer_t; +#define _hi(p,v) ((p).hi=(_cas_field_t)(v)) +#define _lo(p,v) ((p).lo=(_cas_field_t)(v)) +#define _hi_eq(p,v) ((p).hi==(_cas_field_t)(v)) +#define _lo_eq(p,v) ((p).lo==(_cas_field_t)(v)) + inline int cas(volatile cas_pointer_t* mem, cas_pointer_t old_val, cas_pointer_t new_val) { char success; -- cgit v1.1-2-g2b99