summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-01-27 01:28:04 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-01-27 01:28:04 +0100
commit4e1cc10bb6763bb034acab3e12b6dce0d5570386 (patch)
treee208af82f74f755d070339a8e18c8928ddd97ed8
parent7f26ba38df551b757e8ff5adbd2ea4ff406cb870 (diff)
downloadlock_free-4e1cc10bb6763bb034acab3e12b6dce0d5570386.zip
lock_free-4e1cc10bb6763bb034acab3e12b6dce0d5570386.tar.gz
factorise cas.h
-rw-r--r--cas.h35
1 files 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;