ck_ring: Add modulo logic to ck_ring_size and CK_RING_SIZE.

ck_pring
Samy Al Bahra 14 years ago
parent faf3084c26
commit 5889498c16

@ -67,7 +67,7 @@
\ \
c = ck_pr_load_uint(&ring->c_head); \ c = ck_pr_load_uint(&ring->c_head); \
p = ck_pr_load_uint(&ring->p_tail); \ p = ck_pr_load_uint(&ring->p_tail); \
return (p - c); \ return (p - c) & ring->mask; \
} \ } \
CK_CC_INLINE static unsigned int \ CK_CC_INLINE static unsigned int \
ck_ring_capacity_##name(struct ck_ring_##name *ring) \ 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); c = ck_pr_load_uint(&ring->c_head);
p = ck_pr_load_uint(&ring->p_tail); p = ck_pr_load_uint(&ring->p_tail);
return (p - c); return (p - c) & ring->mask;
} }
CK_CC_INLINE static unsigned int CK_CC_INLINE static unsigned int

@ -73,7 +73,7 @@ test(void *c)
assert(entries != NULL); assert(entries != NULL);
if (ck_ring_size(ring) != 0) { 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)); ck_ring_size(ring));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -83,6 +83,7 @@ test(void *c)
entries[i].tid = 0; entries[i].tid = 0;
r = ck_ring_enqueue_spsc(ring, entries + i); r = ck_ring_enqueue_spsc(ring, entries + i);
assert(r != false);
} }
if (ck_ring_size(ring) != (unsigned int)size) { if (ck_ring_size(ring) != (unsigned int)size) {

Loading…
Cancel
Save