Fix: add missing destroy functions to queues/stack APIs
[urcu.git] / urcu / static / wfqueue.h
index 77828ca1d8c046f41d3da76c8f7d5b0253e076ba..df9f62f28bafa189a5b2f0d61fcbfce8b978b7b4 100644 (file)
@@ -65,6 +65,12 @@ static inline void _cds_wfq_init(struct cds_wfq_queue *q)
        assert(!ret);
 }
 
+static inline void _cds_wfq_destroy(struct cds_wfq_queue *q)
+{
+       int ret = pthread_mutex_destroy(&q->lock);
+       assert(!ret);
+}
+
 static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
                                    struct cds_wfq_node *node)
 {
@@ -75,7 +81,7 @@ static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
         * structure containing node and setting node->next to NULL before
         * publication.
         */
-       old_tail = uatomic_xchg(&q->tail, node);
+       old_tail = uatomic_xchg(&q->tail, &node->next);
        /*
         * At this point, dequeuers see a NULL old_tail->next, which indicates
         * that the queue is being appended to. The following store will append
@@ -84,6 +90,29 @@ static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
        CMM_STORE_SHARED(*old_tail, node);
 }
 
+/*
+ * Waiting for enqueuer to complete enqueue and return the next node
+ */
+static inline struct cds_wfq_node *
+___cds_wfq_node_sync_next(struct cds_wfq_node *node)
+{
+       struct cds_wfq_node *next;
+       int attempt = 0;
+
+       /*
+        * Adaptative busy-looping waiting for enqueuer to complete enqueue.
+        */
+       while ((next = CMM_LOAD_SHARED(node->next)) == NULL) {
+               if (++attempt >= WFQ_ADAPT_ATTEMPTS) {
+                       (void) poll(NULL, 0, WFQ_WAIT); /* Wait for 10ms */
+                       attempt = 0;
+               } else
+                       caa_cpu_relax();
+       }
+
+       return next;
+}
+
 /*
  * It is valid to reuse and free a dequeued node immediately.
  *
@@ -96,7 +125,6 @@ static inline struct cds_wfq_node *
 ___cds_wfq_dequeue_blocking(struct cds_wfq_queue *q)
 {
        struct cds_wfq_node *node, *next;
-       int attempt = 0;
 
        /*
         * Queue is empty if it only contains the dummy node.
@@ -105,16 +133,8 @@ ___cds_wfq_dequeue_blocking(struct cds_wfq_queue *q)
                return NULL;
        node = q->head;
 
-       /*
-        * Adaptative busy-looping waiting for enqueuer to complete enqueue.
-        */
-       while ((next = CMM_LOAD_SHARED(node->next)) == NULL) {
-               if (++attempt >= WFQ_ADAPT_ATTEMPTS) {
-                       poll(NULL, 0, WFQ_WAIT);        /* Wait for 10ms */
-                       attempt = 0;
-               } else
-                       caa_cpu_relax();
-       }
+       next = ___cds_wfq_node_sync_next(node);
+
        /*
         * Move queue head forward.
         */
This page took 0.02361 seconds and 4 git commands to generate.