X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Fwfqueue.h;h=2ba86248aa7095c4ca83e94b13769c073507a58c;hp=2eaace1c260f99e7562a36649fc5129fdb03cce0;hb=200d100e05ed8e10c47f971939042f2406df92ef;hpb=55d1510c9654293e7a5ecfa30d381a743d3c4bc3 diff --git a/urcu/wfqueue.h b/urcu/wfqueue.h index 2eaace1..2ba8624 100644 --- a/urcu/wfqueue.h +++ b/urcu/wfqueue.h @@ -31,13 +31,11 @@ extern "C" { #endif -#if (!defined(_GNU_SOURCE) && !defined(_LGPL_SOURCE)) -#error "Dynamic loader LGPL wrappers not implemented yet" +#ifndef CDS_WFQ_DEPRECATED +#define CDS_WFQ_DEPRECATED \ + CDS_DEPRECATED("urcu/wfqueue.h is deprecated. Please use urcu/wfcqueue.h instead.") #endif -#define WFQ_ADAPT_ATTEMPTS 10 /* Retry if being set */ -#define WFQ_WAIT 10 /* Wait 10 ms if being set */ - /* * Queue with wait-free enqueue/blocking dequeue. * This implementation adds a dummy head node when the queue is empty to ensure @@ -47,111 +45,79 @@ extern "C" { * Paul E. McKenney. */ -struct wfq_node { - struct wfq_node *next; +struct cds_wfq_node { + struct cds_wfq_node *next; }; -struct wfq_queue { - struct wfq_node *head, **tail; - struct wfq_node dummy; /* Dummy node */ +struct cds_wfq_queue { + struct cds_wfq_node *head, **tail; + struct cds_wfq_node dummy; /* Dummy node */ pthread_mutex_t lock; }; -void wfq_node_init(struct wfq_node *node) +#ifdef _LGPL_SOURCE + +#include + +static inline CDS_WFQ_DEPRECATED +void cds_wfq_node_init(struct cds_wfq_node *node) { - node->next = NULL; + _cds_wfq_node_init(node); } -void wfq_init(struct wfq_queue *q) +static inline CDS_WFQ_DEPRECATED +void cds_wfq_init(struct cds_wfq_queue *q) { - int ret; - - wfq_node_init(&q->dummy); - /* Set queue head and tail */ - q->head = &q->dummy; - q->tail = &q->dummy.next; - ret = pthread_mutex_init(&q->lock, NULL); - assert(!ret); + _cds_wfq_init(q); } -void wfq_enqueue(struct wfq_queue *q, struct wfq_node *node) +static inline CDS_WFQ_DEPRECATED +void cds_wfq_destroy(struct cds_wfq_queue *q) { - struct wfq_node **old_tail; - - /* - * uatomic_xchg() implicit memory barrier orders earlier stores to data - * structure containing node and setting node->next to NULL before - * publication. - */ - old_tail = uatomic_xchg(&q->tail, node); - /* - * At this point, dequeuers see a NULL old_tail->next, which indicates - * that the queue is being appended to. The following store will append - * "node" to the queue from a dequeuer perspective. - */ - STORE_SHARED(*old_tail, node); + _cds_wfq_destroy(q); } -/* - * It is valid to reuse and free a dequeued node immediately. - * - * No need to go on a waitqueue here, as there is no possible state in which the - * list could cause dequeue to busy-loop needlessly while waiting for another - * thread to be scheduled. The queue appears empty until tail->next is set by - * enqueue. - */ -struct wfq_node * -__wfq_dequeue_blocking(struct wfq_queue *q) +static inline CDS_WFQ_DEPRECATED +void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node) +{ + _cds_wfq_enqueue(q, node); +} + +static inline CDS_WFQ_DEPRECATED +struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) { - struct wfq_node *node, *next; - int attempt = 0; - - /* - * Queue is empty if it only contains the dummy node. - */ - if (q->head == &q->dummy && LOAD_SHARED(q->tail) == &q->dummy.next) - return NULL; - node = q->head; - - /* - * Adaptative busy-looping waiting for enqueuer to complete enqueue. - */ - while ((next = LOAD_SHARED(node->next)) == NULL) { - if (++attempt >= WFQ_ADAPT_ATTEMPTS) { - poll(NULL, 0, WFQ_WAIT); /* Wait for 10ms */ - attempt = 0; - } else - cpu_relax(); - } - /* - * Move queue head forward. - */ - q->head = next; - /* - * Requeue dummy node if we just dequeued it. - */ - if (node == &q->dummy) { - wfq_node_init(node); - wfq_enqueue(q, node); - return __wfq_dequeue_blocking(q); - } - return node; + return ___cds_wfq_dequeue_blocking(q); } -struct wfq_node * -wfq_dequeue_blocking(struct wfq_queue *q) +static inline CDS_WFQ_DEPRECATED +struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) { - struct wfq_node *retnode; - int ret; - - ret = pthread_mutex_lock(&q->lock); - assert(!ret); - retnode = __wfq_dequeue_blocking(q); - ret = pthread_mutex_unlock(&q->lock); - assert(!ret); - return retnode; + return _cds_wfq_dequeue_blocking(q); } +#else /* !_LGPL_SOURCE */ + +extern CDS_WFQ_DEPRECATED +void cds_wfq_node_init(struct cds_wfq_node *node); + +extern CDS_WFQ_DEPRECATED +void cds_wfq_init(struct cds_wfq_queue *q); + +extern CDS_WFQ_DEPRECATED +void cds_wfq_destroy(struct cds_wfq_queue *q); + +extern CDS_WFQ_DEPRECATED +void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node); + +/* __cds_wfq_dequeue_blocking: caller ensures mutual exclusion between dequeues */ +extern CDS_WFQ_DEPRECATED +struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); + +extern CDS_WFQ_DEPRECATED +struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); + +#endif /* !_LGPL_SOURCE */ + #ifdef __cplusplus } #endif