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) {