[dpdk-dev] [PATCH v2 13/14] ring: create common function for updating tail idx

Bruce Richardson bruce.richardson at intel.com
Tue Mar 7 12:32:16 CET 2017


Both producer and consumer use the same logic for updating the tail
index so merge into a single function.

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 lib/librte_ring/rte_ring.h | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index d2ebc9d..6499a8d 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -344,6 +344,19 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
 	} \
 } while (0)
 
+static inline __attribute__((always_inline)) void
+update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val)
+{
+	/*
+	 * If there are other enqueues/dequeues in progress that preceded us,
+	 * we need to wait for them to complete
+	 */
+	while (unlikely(ht->tail != old_val))
+		rte_pause();
+
+	ht->tail = new_val;
+}
+
 /**
  * @internal This function updates the producer head for enqueue
  *
@@ -443,15 +456,7 @@ __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
 	ENQUEUE_PTRS();
 	rte_smp_wmb();
 
-	/*
-	 * If there are other enqueues in progress that preceded us,
-	 * we need to wait for them to complete
-	 */
-	while (unlikely(r->prod.tail != prod_head))
-		rte_pause();
-
-	r->prod.tail = prod_next;
-
+	update_tail(&r->prod, prod_head, prod_next);
 end:
 	if (free_space != NULL)
 		*free_space = free_entries - n;
@@ -556,14 +561,7 @@ __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
 	DEQUEUE_PTRS();
 	rte_smp_rmb();
 
-	/*
-	 * If there are other enqueues in progress that preceded us,
-	 * we need to wait for them to complete
-	 */
-	while (unlikely(r->cons.tail != cons_head))
-		rte_pause();
-
-	r->cons.tail = cons_next;
+	update_tail(&r->cons, cons_head, cons_next);
 
 end:
 	if (available != NULL)
-- 
2.9.3



More information about the dev mailing list