From e99dc95b4cb3ea7ea1cf5fb1606319667bff83cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 8 Nov 2009 02:10:49 +0100 Subject: union ptr_u and lf_eql added to lf_cas --- lf_cas.h | 6 ++++++ lf_fifo.c | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lf_cas.h b/lf_cas.h index 1a21bf1..ff6270a 100644 --- a/lf_cas.h +++ b/lf_cas.h @@ -39,6 +39,12 @@ typedef struct lf_pointer { volatile unsigned int count; } lf_pointer_t; +union ptr_u { + lf_pointer_t ptr; + volatile long long concat; +}; + +#define lf_eql(ptra,ptrb) (((union ptr_u)(ptra)).concat == ((union ptr_u)(ptrb)).concat) /* CMPXCHG8B m64 Compare EDX:EAX with m64. If equal, set ZF and load ECX:EBX into m64. Else, clear ZF and load m64 into EDX:EAX. */ static inline unsigned int cas( volatile lf_pointer_t *mem, diff --git a/lf_fifo.c b/lf_fifo.c index 1f4ab90..963d53b 100644 --- a/lf_fifo.c +++ b/lf_fifo.c @@ -28,11 +28,6 @@ #include "lf_fifo.h" #include "stdlib.h" -union ptr_u { - lf_pointer_t ptr; - volatile long long concat; -}; - /* initialize an empty lf_fifo structure */ void lf_fifo_init( lf_fifo_t *q ) { q->head.ptr = q->tail.ptr = NULL; @@ -65,7 +60,7 @@ void lf_fifo_push( lf_fifo_t *q, lf_pointer_t *node ) { /* snapshot last through tail */ last = *tail.ptr; /* if tail is still consistant */ - if (((union ptr_u)tail).concat == ((union ptr_u)q->tail).concat) { + if lf_eql(tail,q->tail) { /* if last is the last node */ if (last.ptr == NULL) { tmp.count = last.count+1; @@ -105,7 +100,7 @@ lf_pointer_t* pop( lf_fifo_t *q ) { cas( &q->tail, tail, tmp ); } else { /* get the node ptr */ - node = (lf_pointer_t *)head.ptr; + node = (lf_pointer_t*)head.ptr; /* get the next head ready */ tmp.ptr = node->ptr; tmp.count = head.count+1; -- cgit v1.1-2-g2b99