X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Frculfqueue.h;h=f229cc77ca8d8a741a516dc4f3bbcae2cd67a90e;hp=d5c74288831d32e810a045fc068c668e7d60347f;hb=3d02c34dba0edc4a3554a3862a2ae96d77b3b4e8;hpb=eaf2c3f4b9041d2a6a85d7f9e56f6014603367d4 diff --git a/urcu/rculfqueue.h b/urcu/rculfqueue.h index d5c7428..f229cc7 100644 --- a/urcu/rculfqueue.h +++ b/urcu/rculfqueue.h @@ -30,10 +30,6 @@ extern "C" { #endif -#if (!defined(_GNU_SOURCE) && !defined(_LGPL_SOURCE)) -#error "Dynamic loader LGPL wrappers not implemented yet" -#endif - /* * Lock-free RCU queue using reference counting. Enqueue and dequeue operations * hold a RCU read lock to deal with cmpxchg ABA problem. This implementation @@ -44,8 +40,6 @@ extern "C" { * which point their reference count will be decremented. */ -#define URCU_LFQ_PERMANENT_REF 128 - struct rcu_lfq_node { struct rcu_lfq_node *next; struct urcu_ref ref; @@ -56,59 +50,20 @@ struct rcu_lfq_queue { struct rcu_lfq_node init; /* Dummy initialization node */ }; -void rcu_lfq_node_init(struct rcu_lfq_node *node) -{ - node->next = NULL; - urcu_ref_init(&node->ref); -} - -void rcu_lfq_init(struct rcu_lfq_queue *q) -{ - rcu_lfq_node_init(&q->init); - /* Make sure the initial node is never freed. */ - urcu_ref_set(&q->init.ref, URCU_LFQ_PERMANENT_REF); - q->head = q->tail = &q->init; -} +#ifdef _LGPL_SOURCE -void rcu_lfq_enqueue(struct rcu_lfq_queue *q, struct rcu_lfq_node *node) -{ - urcu_ref_get(&node->ref); +#include - /* - * uatomic_cmpxchg() implicit memory barrier orders earlier stores to - * node before publication. - */ +#define rcu_lfq_node_init _rcu_lfq_node_init +#define rcu_lfq_init _rcu_lfq_init +#define rcu_lfq_enqueue _rcu_lfq_enqueue +#define rcu_lfq_dequeue _rcu_lfq_dequeue - for (;;) { - struct rcu_lfq_node *tail, *next; +#else /* !_LGPL_SOURCE */ - rcu_read_lock(); - tail = rcu_dereference(q->tail); - /* - * Typically expect tail->next to be NULL. - */ - next = uatomic_cmpxchg(&tail->next, NULL, node); - if (next == NULL) { - /* - * Tail was at the end of queue, we successfully - * appended to it. - * Now move tail (another enqueue might beat - * us to it, that's fine). - */ - uatomic_cmpxchg(&q->tail, tail, node); - rcu_read_unlock(); - return; - } else { - /* - * Failure to append to current tail. Help moving tail - * further and retry. - */ - uatomic_cmpxchg(&q->tail, tail, next); - rcu_read_unlock(); - continue; - } - } -} +extern void rcu_lfq_node_init(struct rcu_lfq_node *node); +extern void rcu_lfq_init(struct rcu_lfq_queue *q); +extern void rcu_lfq_enqueue(struct rcu_lfq_queue *q, struct rcu_lfq_node *node); /* * The entry returned by dequeue must be taken care of by doing a urcu_ref_put, @@ -120,32 +75,10 @@ void rcu_lfq_enqueue(struct rcu_lfq_queue *q, struct rcu_lfq_node *node) * modified/re-used/freed until the reference count reaches zero and a grace * period has elapsed (after the refcount reached 0). */ -struct rcu_lfq_node * -rcu_lfq_dequeue(struct rcu_lfq_queue *q, void (*release)(struct urcu_ref *)) -{ - for (;;) { - struct rcu_lfq_node *head, *next; +extern struct rcu_lfq_node * +rcu_lfq_dequeue(struct rcu_lfq_queue *q, void (*release)(struct urcu_ref *)); - rcu_read_lock(); - head = rcu_dereference(q->head); - next = rcu_dereference(head->next); - if (next) { - if (uatomic_cmpxchg(&q->head, head, next) == head) { - rcu_read_unlock(); - urcu_ref_put(&head->ref, release); - return next; - } else { - /* Concurrently pushed, retry */ - rcu_read_unlock(); - continue; - } - } else { - /* Empty */ - rcu_read_unlock(); - return NULL; - } - } -} +#endif /* !_LGPL_SOURCE */ #ifdef __cplusplus }