From 7f35cbee1ba1d65f4134e97d557876043144349c Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Tue, 2 Oct 2012 16:07:27 -0400 Subject: [PATCH] ck_ring: Use SPSC enqueue as SPMC enqueue. --- include/ck_ring.h | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/include/ck_ring.h b/include/ck_ring.h index 48d90cb..b73988c 100644 --- a/include/ck_ring.h +++ b/include/ck_ring.h @@ -165,9 +165,9 @@ ck_ring_enqueue_spsc(struct ck_ring *ring, void *entry) consumer = ck_pr_load_uint(&ring->c_head); producer = ring->p_tail; - delta = (producer + 1) & mask; + delta = producer + 1; - if (delta == (consumer & mask)) + if ((delta & mask) == (consumer & mask)) return false; ring->ring[producer & mask] = entry; @@ -177,7 +177,7 @@ ck_ring_enqueue_spsc(struct ck_ring *ring, void *entry) * that the slot is available for consumption. */ ck_pr_fence_store(); - ck_pr_store_uint(&ring->p_tail, producer + 1); + ck_pr_store_uint(&ring->p_tail, delta); return true; } @@ -217,25 +217,8 @@ ck_ring_dequeue_spsc(struct ck_ring *ring, void *data) CK_CC_INLINE static bool ck_ring_enqueue_spmc(struct ck_ring *ring, void *entry) { - unsigned int consumer, producer, delta; - unsigned int mask = ring->mask; - consumer = ck_pr_load_uint(&ring->c_head); - producer = ring->p_tail; - delta = producer + 1; - - if ((delta & mask) == (consumer & mask)) - return false; - - ring->ring[producer & mask] = entry; - - /* - * Make sure to update slot value before indicating - * that the slot is available for consumption. - */ - ck_pr_fence_store(); - ck_pr_store_uint(&ring->p_tail, delta); - return true; + return ck_ring_enqueue_spsc(ring, entry); } CK_CC_INLINE static bool