diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-01-27 01:28:04 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-01-27 01:28:04 +0100 |
commit | 4e1cc10bb6763bb034acab3e12b6dce0d5570386 (patch) | |
tree | e208af82f74f755d070339a8e18c8928ddd97ed8 /cas.h | |
parent | 7f26ba38df551b757e8ff5adbd2ea4ff406cb870 (diff) | |
download | lock_free-4e1cc10bb6763bb034acab3e12b6dce0d5570386.zip lock_free-4e1cc10bb6763bb034acab3e12b6dce0d5570386.tar.gz |
factorise cas.h
Diffstat (limited to 'cas.h')
-rw-r--r-- | cas.h | 35 |
1 files changed, 15 insertions, 20 deletions
@@ -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; |