From 5889498c16abe882b1a65c2dd553981be85ef7c3 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Mon, 25 Jul 2011 10:19:53 -0400 Subject: [PATCH] ck_ring: Add modulo logic to ck_ring_size and CK_RING_SIZE. --- include/ck_ring.h | 4 ++-- regressions/ck_ring/validate/ck_ring_spsc.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/ck_ring.h b/include/ck_ring.h index 317bf76..4a7a31f 100644 --- a/include/ck_ring.h +++ b/include/ck_ring.h @@ -67,7 +67,7 @@ \ c = ck_pr_load_uint(&ring->c_head); \ p = ck_pr_load_uint(&ring->p_tail); \ - return (p - c); \ + return (p - c) & ring->mask; \ } \ CK_CC_INLINE static unsigned int \ ck_ring_capacity_##name(struct ck_ring_##name *ring) \ @@ -148,7 +148,7 @@ ck_ring_size(struct ck_ring *ring) c = ck_pr_load_uint(&ring->c_head); p = ck_pr_load_uint(&ring->p_tail); - return (p - c); + return (p - c) & ring->mask; } CK_CC_INLINE static unsigned int diff --git a/regressions/ck_ring/validate/ck_ring_spsc.c b/regressions/ck_ring/validate/ck_ring_spsc.c index d6e786c..238a770 100644 --- a/regressions/ck_ring/validate/ck_ring_spsc.c +++ b/regressions/ck_ring/validate/ck_ring_spsc.c @@ -73,7 +73,7 @@ test(void *c) assert(entries != NULL); if (ck_ring_size(ring) != 0) { - fprintf(stderr, "Less entries than expected: %u > 0\n", + fprintf(stderr, "More entries than expected: %u > 0\n", ck_ring_size(ring)); exit(EXIT_FAILURE); } @@ -83,6 +83,7 @@ test(void *c) entries[i].tid = 0; r = ck_ring_enqueue_spsc(ring, entries + i); + assert(r != false); } if (ck_ring_size(ring) != (unsigned int)size) {